1

I have a rest call to a server which returns me something that looks like this:

response.searchResult = ["{\"key1\":\"value1\",
                          \"key2\":\"value2\",
                          \"key3\":\"value3\"}"]

How can I extract all key-value pairs into a json array? Or at the very least, how can I search for the value associated with a specific key, lets say "key2" from the example?

1
  • can you do like this JSON.parse(["{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}"]) Commented Jul 20, 2015 at 12:50

1 Answer 1

2

Just run json.parse on the array entry:

response.searchResult = ["{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}"];
var jsonResult = JSON.parse(response.searchResult[0]);
console.log(jsonResult);
Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what i was looking for, thank you Mathew :).

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.