JSON Escape / Unescape
Escape special characters in a string for use inside JSON, or unescape a JSON string value. Handles quotes and backslashes.
JSON Escape / Unescape
How it works
Escape: we wrap in quotes and use JSON.stringify on the string. Unescape: we parse a quoted JSON string.
When to use it
Use when building JSON by hand or fixing malformed string values.
Frequently asked questions
Unicode?
JSON.stringify produces \uXXXX for non-ASCII when needed.
Newlines?
Escaped as \n; unescape restores them.