Shivank Verma Shivank Verma - 4 months ago 10
JSON Question

How to convert JavaScript object containing json string

I am having problem parsing JSON string into JS object .Please tell how to convert JavaScript object :

Object {d: "[{"worker_id":1,"worker_name":"Shivank"}]"}


into

Object { d: [{ "worker_id": 1, "worker_name": "Shivank" }] }


I have tried using

JSON.parse(data)


and

var dataFinal = JSON.stringify(data);
var d1 = eval('(' +dataFinal+ ')');

Answer

You have an object where one property value contains JSON so you only need to convert that value

Try

data.d= JSON.parse(data.d);
Comments