0

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+ ')');
2
  • 1
    What have you tried? Commented Jul 27, 2016 at 13:49
  • I have edited the question Please have a look at it now Commented Jul 27, 2016 at 13:53

2 Answers 2

2

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);
Sign up to request clarification or add additional context in comments.

Comments

1

Assuming your data is as below, which d is having stringified json data

var data = {d: "[{\"worker_id\":1,\"worker_name\":\"Shivank\"}]"}

console.log(data);

You can parse JSON and assign to d key

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

console.log(data); // required output

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.