Skip to content

Instantly share code, notes, and snippets.

@bsommardahl
Last active March 19, 2021 22:00
Show Gist options
  • Save bsommardahl/5a7cdc6fb5d4c1fe4003df3721e1425d to your computer and use it in GitHub Desktop.
Save bsommardahl/5a7cdc6fb5d4c1fe4003df3721e1425d to your computer and use it in GitHub Desktop.
Parsing JSON string with nested JSON strings
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