JSON Forge
100% Client-Side: your data is never sent to a server

JSON errors

Bad control character in string literal in JSON

The JSON below reproduces this error. See where it breaks, press Fix JSON, or paste your own text.

Loading editor…
Paste or type JSON on the left to explore it as a tree.
Empty🔒 Processed locally in your browser

What the error means

Inside a JSON string, characters below U+0020 (new lines, tabs and other control characters) must be written as escape sequences, and a backslash must start a valid escape. A raw line break inside a string, or a backslash followed by an unknown character, is rejected.

The message looks like this in Chrome, Edge and Node.js (Firefox and Safari use different wording for the same problems):

Bad control character in string literal in JSON at position 12 (line 1 column 13)
Bad escaped character in JSON at position 13 (line 1 column 14)

Common causes

A real line break inside a string

Pasting multi-line text between the quotes puts an actual newline in the string. Write it as \n instead.

Broken:  {"note": "line one
line two"}
Valid:   {"note": "line one\nline two"}

A raw tab character

Tabs copied from a spreadsheet or a code editor are control characters too. Use \t.

Windows paths and other backslashes

A backslash begins an escape such as \n or \u. In C:\Users the \U is not a valid escape. Double every backslash.

Broken:  {"path": "C:\Users\ada"}
Valid:   {"path": "C:\\Users\\ada"}

How to find the problem

  1. Paste the text that you passed to JSON.parse into the editor above. The status bar shows the line and column of the first problem, and Go to error jumps there.
  2. Remember that the position in the message is where the parser gave up, which is often one token after the real mistake. Look at the character before it as well.
  3. If the text came from a request, log the raw response text before parsing it. In the browser, open the Network tab, select the request and read the Response tab.

Let JSON.stringify do the escaping

const note = "line one\nline two";
const path = "C:\\Users\\ada";
const json = JSON.stringify({ note, path });
// {"note":"line one\nline two","path":"C:\\Users\\ada"}

Frequently asked questions

Which escapes are valid in JSON?

\" \\ \/ \b \f \n \r \t and \uXXXX for any code point. Anything else after a backslash is an error.

Does Fix JSON handle this?

Yes, it escapes line breaks inside strings and repairs common backslash problems. Check the result for paths, because the intended meaning is sometimes ambiguous.

Related errors

All common JSON errors · JSON Validator