Reputation: 441
I have a json response which I have got after
result = JSON.parse(result.value);
json response
"{"name":"For ","children":["{ \"name\":\"sxsm cnklsd\"}","{ \"name\":\"smd csdm\"}"]}".
Now I am trying to convert this in to a structure as:
{
"name": "For ",
"children": [
{
"name": "sxsm cnklsd"
},
{
"name": "smd csdm"
}
]
}
I tried to double parsing , stringify and then parse but nothing seems to be working. Please help.
Upvotes: 0
Views: 70
Reputation:
Parse the JSON as you have done:
> result = JSON.parse(result.value);
< {"name":"For ","children":["{ \"name\":\"sxsm cnklsd\"}","{ \"name\":\"smd csdm\"}"]}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
children
is an array containing two JSON strings. Parse them:
> result.children = result.children.map(JSON.parse)
> result
< {"name":"For ", "children":[{ "name":"sxsm cnklsd"}, {"name":"smd csdm"}]}
Upvotes: 1