How do I shape the returned JSON object into array in Javascript/JQUery?

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?

Answers


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()


Need Your Help

Collision on one side only in cocos2d / box2d

ios cocos2d-iphone box2d collision-detection

I am working on an application using cocos2d and box2d within iOS/xcode.

Django REST framework - What is the correct way of registering / validating new users?

django serialization django-models django-rest-framework user-registration

I've only started using the Django REST framework recently. I want to create a user. Before (without Django REST framework) I used to create users with the following logic (using the User model in ...