I need help converting the object I receive from the server into a JSON file for use in a d3.js chart:
data = {
"dog ":"5",
"cat ":"4",
"fish ":"12",
}
The desired output is:
{
"name" : "animal",
"children" : [
{"name":"dog", "value": 5},
{"name":"cat", "value": 4},
{"name":"fish", "value": 10}
]
}
This is what I have so far:
var jsonText = [] ;
for ( key in data) {
jsonText.push({name : key.trim(), value : parseInt(data[key])});
}
However, when I try to print out the object, I get:
[object Object],[object Object],[object Object]
I am also unsure how to add other attributes to the JSON file. Any suggestions would be greatly appreciated.