Last active
December 22, 2015 00:12
-
-
Save hattmarris/4b963ddb2edda2c6a205 to your computer and use it in GitHub Desktop.
parse JSON
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
/** | |
* 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