Fix newlines in JSON strings (no upload)

TL;DR: A JSON string can’t contain a raw line break. Replace real newlines with \\n, then validate locally (no upload).

How to represent newlines correctly inside JSON strings and avoid parsing errors.

Why newlines break JSON

In strict JSON, control characters (U+0000–U+001F) are not allowed inside a quoted string unless they are escaped. A real newline (U+000A) inside "..." makes the JSON invalid, so parsers fail with errors like “bad control character”, “unexpected token”, or “unterminated string”.

What the broken input looks like

This is invalid JSON because the string contains a raw line break:

{"msg":"line1
line2"}

The fix: escape as \\n

Represent the newline using the \\n escape sequence:

{"msg":"line1\\nline2"}

Fast no-upload workflow

  1. Escape/unescape safely with JSON String Escape/Unescape.
  2. Validate the full JSON with JSON Validator.
  3. If the input has comments or trailing commas, normalize with JSON Repair.

Edge cases to watch

  • Windows newlines: \\r\\n may appear (CRLF). Both must be escaped inside JSON strings.
  • Double-escaped logs: you may see \\\\n in logs, which can mean “a literal backslash + n”.
  • Copy/paste: content copied from terminals can include invisible characters. Validate first.

Trust note: All processing happens locally in your browser. Files are never uploaded.

FAQ

Can I just “remove newlines”? You can, but it changes the data. Escaping preserves the newline in the parsed value.

Is it safe to use online converters? If privacy matters, prefer no-upload tools and avoid pasting secrets into upload-based sites.

Privacy & Security
All processing happens locally in your browser. Files are never uploaded.