Created
May 2, 2012 14:05
-
-
Save gsf/2576755 to your computer and use it in GitHub Desktop.
JSON stringifying and parsing in the Chrome console
This file contains 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
> JSON.stringify({aList: '\tthing1\n\tthing2\n'}) | |
"{"aList":"\tthing1\n\tthing2\n"}" | |
> JSON.parse('{"aList":"\tthing1\n\tthing2\n"}') | |
▼ SyntaxError: Unexpected token | |
▶ arguments: Array[1] | |
▶ get message: function getter() { [native code] } | |
▶ get stack: function getter() { [native code] } | |
▶ set message: function setter() { [native code] } | |
▶ set stack: function setter() { [native code] } | |
type: "unexpected_token" | |
▶ __proto__: Error | |
> JSON.parse('{"aList":"\\tthing1\\n\\tthing2\\n"}') | |
▼ Object | |
aList: " thing1↵ thing2↵" | |
▶ __proto__: Object | |
> JSON.parse(JSON.stringify({aList: '\tthing1\n\tthing2\n'})) | |
▼ Object | |
aList: " thing1↵ thing2↵" | |
▶ __proto__: Object | |
> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment