javascript - Convert regular json to flare.json for d3.js? -
i have json so:
{ "a": { "x": { "y": { "a": {}, "z": {}, "b": {} } }, "c": {}, "b": { "c": { "d": {} } }, "d": {}, ... } }
is there quick way convert flare.json format?
like so:
{ "name":"a", "children":[ { "name":"x", "children": { "name":"y", "children":[{"name":"a", "size":0},{"name":"z","size":0},{"name":"b","size":0}] ... }
thank you.
i have come series of regex transforms this.
#replace-this #with-this ^\s*" \{"name":" : \{\}, \}, : \{\} \} ": \{$ ","children":\[ ^\s*\}, \]\}, ^\s*\} \]\} #in order
and delete first , last line (should {
, ]}
)
on applying these regex transforms,
this:
{ "a": { "x": { "y": { "a": {}, "z": {}, "b": {} } }, "c": {}, "b": { "c": { "d": {} } }, "d": {} }
}
will become this:
{ "name": "a", "children": [{ "name": "x", "children": [{ "name": "y", "children": [{ "name": "a" }, { "name": "z" }, { "name": "b" }] }] }, { "name": "c" }, { "name": "b", "children": [{ "name": "c", "children": [{ "name": "d" }] }] }, { "name": "d" }] }
which can used of d3js examples.
Comments
Post a Comment