Here is the raw json
data:
json_file <- '{"name":"Doe, John","group":"Red","age":{"v_0":24}}
{"name":"Doe, Jane","group":"Green","age":{"v_0":31}}
{"name":"Smith, Joan","group":"Yellow","age":{"v_0":22}}'
When I want to convert json_file
to a data frame:
library(RJSONIO)
json_file <- fromJSON(json_file)
I get this error:
Error: parse error: trailing garbage
:"Red","age":{"v_0":24}} {"name":"Doe, Jane","group":"Gr
(right here) ------^
I know if I change the raw data to the following data, everything would be fine:
json_file <- '[{"name":"Doe, John","group":"Red","age":{"v_0":24}},
{"name":"Doe, Jane","group":"Green","age":{"v_0":31}},
{"name":"Smith, Joan","group":"Yellow","age":{"v_0":22}}]'
But actually I would like to know:
1) How to get data frame from the raw data without splitting its objects using [
, ,
and ]
?
2) If there is no way, how to split objects in a large json
file by adding ,
to end of each line except the last line, and also adding [
and ]
to the first and last line of the file?