I am trying to add a custom graph attribute to an igraph object. I use the code
graph = set_graph_attr(graph, "directed", FALSE)
data_json <- d3_igraph(igraph)
write(data_json, "graph.json")
and the output appears as
{
"nodes" [
{
"name": "something"
},
{
"name": "something_else"
}
],
"links": [
{
"source": "something",
"target": "something_else"
}
],
"attributes": {
"directed": false
}
}
The added attribute goes into an attributes section of the json, but what I would really like to output is:
{
"nodes" [
{
"name": "something"
},
{
"name": "something_else"
}
],
"links": [
{
"source": "something",
"target": "something_else"
}
],
"attributes": {
},
"directed": false
}
where the new attribute is added at the top level of the json rather than in the attributes section. Is that possible? Eventually the plan is to add several custom attributes including metadata with a more complex structure.
The example isn't fully reproducible, but the development version of the CRAN package rjsoncons has
j_patch_apply(), which allows one to 'patch' a JSON document as illustrated at the JSON patch web site. So afterone should be able to do something like