Last active
March 19, 2021 22:00
-
-
Save bsommardahl/5a7cdc6fb5d4c1fe4003df3721e1425d to your computer and use it in GitHub Desktop.
Parsing JSON string with nested JSON strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const json = "[{'id': 702, 'data': '{"color":"red","age":"32"}'}, {'id': 850, 'data': '{"color":"blue","age":"25"}'}, {'id': 941, 'data': '{"color":"yellow","age":"12"}'}]"; //cannot change the json. This comes from another system | |
const arr = JSON.parse(json); //error here | |
const expected = [{'id': 702, 'data': '{"color":"red","age":"32"}'}, {'id': 850, 'data': '{"color":"blue","age":"25"}'}, {'id': 941, 'data': '{"color":"yellow","age":"12"}'}]; | |
console.log(arr); | |
const success = expected === arr; | |
//should be true, but getting error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment