JSON Escape / Unescape

Escape or unescape characters from input JSON content.



The following characters are reserved in JSON and must be replaced with their corresponding entities in JSON:

Character Description Is replaced with
Backspace \b
Form feed \f
Newline \n
Carriage return \r
Tab \t
Double quote \"
Backslash \\

What is JSON?
  • JSON stands for JavaScript Object Notation
  • JSON is a lightweight data-interchange format
  • JSON is plain text written in JavaScript object notation
  • JSON is used to send data between computers
  • JSON is language independent
  • The JSON syntax is derived from JavaScript object notation, but the JSON format is text only.
  • Code for reading and generating JSON exists in many programming languages.
  • The JSON format was originally specified by Douglas Crockford.

What is JSON escape?

JSON is pretty liberal. The only characters you must escape are \ , " , and control codes (anything less than U+0020). This structure of escaping is specific to JSON. You'll need a JSON specific function. All of the escapes can be written as \uXXXX where XXXX is the UTF-16 code unit¹ for that character.
JSON is based on JavaScript, but it's not the same thing. If you're writing an object literal inside JavaScript code, fine; if you actually need JSON, you need to use " . With double-quoted strings, you won't need to escape the ' . (And if you did want a literal " in the string, you'd use \" .)

Why should I use JSON?

To understand the usefulness and importance of JSON, we'll have to understand a bit about the history of interactivity on the web. In the early 2000s, interactivity on the web began to transform. At the time, the browser served mainly as a dumb client to display information, and the server did all of the hard work to prepare the content for display. When a user clicked on a link or a button in the browser, a request would be sent to the server, the server would prepare the information needed as HTML, and the browser would render the HTML as a new page. This pattern was sluggish and inefficient, requiring the browser to re-render everything on the page even if only a section of the page had changed. Because full-page reloads were costly, web developers looked to newer technologies to improve the overall user experience. Meanwhile, the capability of making web requests in the background while a page was being shown, which had recently been introduced in Internet Explorer 5, was proving to be a viable approach to loading data incrementally for display. Instead of reloading the entire contents of the page, clicking the refresh button would trigger a web request that would load in the background. When the contents were loaded, the data could be manipulated, saved, and displayed on the page using JavaScript, the universal programming language in browsers.