JSON Syntax Highlighting Formatter

Format JSON into clean, indented text that any syntax highlighter can color-code. Nothing leaves your device.

Your result appears here.

What this tool produces

JSON syntax highlighting needs structure to work with. This tool parses your JSON and re-prints it with two-space indentation and one key or array element per line, so that when you paste it into an editor, a documentation page, a slide or a Markdown code fence, the highlighter has a clear token on every line to color: keys, string values, numbers, booleans, null, and the braces and brackets. The tool itself outputs plain text; the colors come from wherever you paste it.

How to use it

  1. Paste JSON into Input. Minified, one-line or badly indented JSON all work.
  2. Click Run tool, or press Ctrl+Enter (Cmd+Enter on a Mac) inside the input box.
  3. If the text is not valid JSON, the parser error appears under the buttons and no output is produced.
  4. Click Copy result and paste it into a json code block in your editor, Markdown file or web page.

How JSON value types are rendered

TypeHow it appearsTypically colored as
String"hello" in double quotesgreen / red
Number42, 3.14 bareblue / purple
Boolean / nulltrue, false, null bareorange / keyword
Key"name": quoted, before a colonbold / teal
Structure{ } [ ]punctuation / dim

Example 1: from one line to a highlightable block

Input (one line, highlights as a single unreadable stripe):

{"id":7,"name":"Ada","admin":false,"tags":["a","b"]}

Formatted for highlighting:

{
  "id": 7,
  "name": "Ada",
  "admin": false,
  "tags": [
    "a",
    "b"
  ]
}

Example 2: Markdown on GitHub, GitLab and docs sites

Wrap the formatted output in a fence with the json language tag. GitHub, GitLab, Bitbucket, VS Code's preview and most static site generators color it automatically:

```json
{
  "id": 7,
  "name": "Ada"
}
```

Use jsonc instead of json if your snippet contains comments, otherwise GitHub marks the comments in red as errors.

Example 3: highlighting JSON on a web page

With Prism or highlight.js loaded, put the formatted text inside a pre/code pair with the language class. Escape < and & inside string values first, or the browser will treat them as markup:

<pre><code class="language-json">{
  "id": 7,
  "note": "a &lt; b"
}</code></pre>

Prism wraps keys in .token.property, strings in .token.string, numbers in .token.number, booleans in .token.boolean, null in .token.null and braces in .token.punctuation; highlight.js uses .hljs-attr, .hljs-string, .hljs-number and .hljs-literal. Target those classes in CSS to change the theme colors.

What formatting changes besides whitespace

The output is produced by parsing and re-serializing, so a few things can differ from your input. Check these before you publish a snippet that must match a source file exactly:

When to use another tool

If you want the colors themselves as HTML you can paste into a page or an email, use the code highlighter, which outputs highlighted markup. To wrap JSON in a ready-made HTML code block, use JSON to HTML. To read and explore a large document with folding and search rather than prepare a snippet, open the JSON viewer. To go the other way and shrink JSON to one line, use the JSON minifier.

Frequently asked questions

Does the output come out in color?

No. The output is indented plain text. Color is applied by whatever renders it next: your code editor, a Markdown fence marked json, a docs site, or a highlighter library such as Prism or highlight.js.

Why format JSON before highlighting it?

Highlighters and readers key off structure: line breaks, indentation and one token per position. A minified blob on a single line highlights as one long stripe. Formatting first gives every key, value and bracket its own place.

Can it highlight invalid JSON?

No. The tool parses first, so invalid input returns a parser error instead of formatted output. Fix the syntax, for example a trailing comma or single quotes, then format again.

Will it preserve my key order?

Yes for ordinary keys. Keys that look like non-negative integers, such as "2", are moved to the start of their object by the JavaScript parser.

Can I get 4-space or tab indentation?

This page always outputs two spaces. Use your editor's reindent command, or the JSON formatter on the home page, which offers 2 spaces, 4 spaces or tabs.

Is my JSON sent to a server?

No. Parsing and formatting run in your browser.