Error parsing JSON file with the jsonlite package

前端 未结 3 2164
情话喂你
情话喂你 2020-11-29 02:38

I\'m trying to read a JSON file into R but I got this error:

Error in parseJSON(txt) : parse error: trailing garbage
      [ 33.816101, -117.979401 ] } { \"         


        
3条回答
  •  攒了一身酷
    2020-11-29 02:56

    This format called ndjson and designed to stream import (including the gzip). Just use this:

    con <- url("http://1usagov.measuredvoice.com/bitly_archive/usagov_bitly_data2013-05-17-1368832207.gz")
    mydata <- jsonlite::stream_in(gzcon(con))
    

    Or alternatively use the curl package for better performance or to customize the http request:

    library(curl)
    con <- curl("http://1usagov.measuredvoice.com/bitly_archive/usagov_bitly_data2013-05-17-1368832207.gz")
    mydata <- jsonlite::stream_in(gzcon(con))
    

提交回复
热议问题