1

I am getting the JSON object from an API in this format:

[{"Id":1,"Name":"A","ParentId":0},
{"Id":2,"Name":"B","ParentId":1},
{"Id":3,"Name":"C","ParentId":2}]

I want to convert it into this format

['Mike', null, 'The President'],
          ['Alice', 'Mike', null],
          ['Bob', 'Jim', 'Bob Sponge'],
          ['Carol', 'Bob', null]

So I can pass it to a function in google api like this

var data = google.visualization.arrayToDataTable(<<DATA>>);

How do I do that? Any advice?

InfoLearner
  • 14,952
  • 20
  • 76
  • 124
  • 3
    http://stackoverflow.com/a/6487185/926460 – Timeless May 10 '12 at 16:51
  • I'm a little confused by your question because the source and destination examples you provided look so different. Is all of the data for the destination format present somewhere in the source or is there another object you'll be combining it with to get the remaining needed data? – John Munsch May 10 '12 at 17:16

1 Answers1

0

You're probably not expecting to get 'Mike' from 'Id', so how this is supposed to work is a little hard to understand, and I'm not sure I really get the question, but did you try:

var myData = $​.makeArray(myObject)​;

jQuery makeArray()

adeneo
  • 312,895
  • 29
  • 395
  • 388