Skip to content

Instantly share code, notes, and snippets.

@gsf
Created May 2, 2012 14:05
Show Gist options
  • Save gsf/2576755 to your computer and use it in GitHub Desktop.
Save gsf/2576755 to your computer and use it in GitHub Desktop.
JSON stringifying and parsing in the Chrome console
> 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