I've seen different conversions done on Stack, and none of them have the results I need. I have a data frame that I imported from an Excel file, manipulated, and want to export as a JSON file. I have tried this:
exportJson <- toJSON(data)
print(exportJson)
write(exportJson, "test.json")
json_data <- fromJSON(file="test.json")
My data looks like this:
Jill Jimmie Alex Jane
Jill Jill 0 Jill Jill
Jimmie 0 Jimmie Jimmie 0
Alex 0 Alex Alex 0
Jane Jane Jane Jane 0
My output looks like this:
{
"Jill": ["Jill",
"0",
"0",
"Jane",
"0",
"0",
"0",
"0",
"0",
"0",
...
when I need it to look like this format:
{
"nodes": [
{
"id": "id1",
"name": "Jill",
"val": 1
},
{
"id": "id2",
"name": "Jill",
"val": 10
},
(...)
],
"links": [
{
"source": "id1",
"target": "id2"
},
(...)
]
}
I've seen ways of converting JSON to a dataframe and I am aware of RJSONIO
, jsonlite
, rjson
, etc. , I've googled it, and maybe I am just missing an obvious answer.