Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

Is there a way in R to add comma's to incorrect JSON format?

$
0
0

I'm trying to work with a JSON file in R, but unfortunately the JSON file is unreadable by jsonlite in its current state. It's missing commas between the objects(arrays elements?). My objective is to form a data frame from this almost-JSON file. Example JSON file, code, and result below.

[
{"Source":"ADSB","Id":43061,"FlightId":"N668XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450} 
{"Source":"ADSB","Id":43062,"FlightId":"N683XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450}
{"Source":"ADSB","Id":43063,"FlightId":"N652XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450}
]

> jsondata = fromJSON("asdf.json")
Error in parse_con(txt, bigint_as_char) : 
  parse error: after array element, I expect ',' or ']'"Heading":280,"Speed":124}   {"Source":"ADSB","Id":43062,"Fl
                     (right here) ------^

After inserting comma's between the objects in the JSON file, it works no problem.

[
{"Source":"ADSB","Id":43061,"FlightId":"N668XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450}, 
{"Source":"ADSB","Id":43062,"FlightId":"N683XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450},
{"Source":"ADSB","Id":43063,"FlightId":"N652XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450},
]
> jsondata = fromJSON("asdf.json")
> names(jsondata)
[1] "Source""Id""FlightId""Latitude""Longitude""Alt"

How do I insert commas throughout this JSON file between all of the curvy brackets? (i.e. "}{" -->"},{" Or is there another way for R to read my incomplete JSON file?

I'm less than a novice, so any help is much appreciated, thanks!!


Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>