Skip to content

Instantly share code, notes, and snippets.

@hattmarris
Last active December 22, 2015 00:12
Show Gist options
  • Save hattmarris/4b963ddb2edda2c6a205 to your computer and use it in GitHub Desktop.
Save hattmarris/4b963ddb2edda2c6a205 to your computer and use it in GitHub Desktop.
parse JSON
/**
* Parse JSON using JavaScript
*/
// arbitrary string "bunch o' junk"
var string = '{"menu":{"id":"file","value":"File","popup":{"menuitem":[{"value":"New","onclick":"CreateNewDoc()"},{"value":"Open","onclick":"OpenDoc()"},{"value":"Close","onclick":"CloseDoc()"}]}}}';
JSON.parse(string);
// parsed and printed in a more "human readable" format
{
"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{
"value": "New",
"onclick": "CreateNewDoc()"
},
{
"value": "Open",
"onclick": "OpenDoc()"
},
{
"value": "Close",
"onclick": "CloseDoc()"
}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment