I have a JSON string:
{ "a1": "root",
"a2": "root data",
"children": [
{ "a1": "child 1",
"a2": "child 1 data",
"children": []
},
{ "a1": "child 2",
"a2": "child 2 data",
"children": [
{ "a1": "child 3",
"a2": "child 3 data",
"children": []
}
]
}
]
}
I want to read this JSON tree structured string into a JavaScript object. I want the class definition of the JavaScript object to be as follows:
function MyNode(){
this.a1 = ""
this.a2 = ""
this.children = []
}
Basically after reading the JSON data structure I would like a have an instance of type MyNode which has the parameters a1 a2 and children, where children or the root node has instances of type MyNode and with data/parameters as specified in the JSON string.
How can I accomplish this? Any pointers would be very helpful.