3

I have the following json object:

var data = [{"name":"abc", "count":"[20.8, 100]"}, {"name":"xyz", "count":"[40, 100]"}]

Notice the array in double quotes : "[20.8, 100]"

I want the double quotes to go

Expected Output:

var data = [{"name":"abc", "count":[20.8, 100]}, {"name":"xyz", "count":[40, 100]}]

Any help would be appreciated

1
  • did you checked my answer ? Commented Jan 6, 2017 at 3:41

2 Answers 2

3

You could use JSON.parse and assign the value to the same property.

var data = [{"name":"abc", "count":"[20.8, 100]"}, {"name":"xyz", "count":"[40, 100]"}];

data.forEach(function (a) {
    a.count = JSON.parse(a.count);
});

console.log(data);

Sign up to request clarification or add additional context in comments.

Comments

0

Step 1 : Iterate the JSON using javaScript for...in loop.

Step 2 : Use JSON.parse() to convert the JSON string("[20.8, 100]") into JSON object([20.8, 100]).

Working demo :

var data = [
             {"name":"abc", "count":"[20.8, 100]"}, 
             {"name":"xyz", "count":"[40, 100]"}
           ];

for (var i in data) {
  data[i].count = JSON.parse(data[i].count);
}

console.log(data);

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.