JSON syntax highlighting you can take with you
JSON syntax highlighting colors keys, strings, numbers, booleans and null differently so readers can parse a document at a glance. Code editors do this automatically, but a blog platform, internal wiki or HTML email often does not. This tool produces the colored version as plain HTML and CSS, so the highlighting travels with the content and needs no JavaScript library on the page where you paste it.
Your JSON is parsed first and re-indented with the Indent you choose, so the published example is always valid and consistently laid out. Invalid input is reported with a line and column instead of being highlighted.
Themes and options
- Light uses a white background with blue keys, dark red strings and green numbers.
- Dark uses a charcoal background with light blue keys, orange strings and pale green numbers.
- Monokai uses the classic dark olive background with cyan keys, yellow strings and purple numbers.
- Line numbers (on by default) adds a numbered gutter. The numbers are styled so they are not selected when a reader copies the code from your page.
- Output embeddable HTML switches the Code tab from the formatted JSON to an HTML snippet. Without it, the Code tab holds plain formatted JSON and the colored version lives on the Preview tab.
Example: the embeddable snippet
With the Monokai theme, line numbers off and the embed option on, the input {"id":7,"ok":true} produces:
<style>body{margin:0;background:#272822;color:#f8f8f2}pre{margin:0;padding:16px;font:13px/1.55 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;white-space:pre}.k{color:#66d9ef}.s{color:#e6db74}.n{color:#ae81ff}.b{color:#fd971f}.u{color:#f92672}.p{color:#a6a6a6}.ln{display:inline-block;width:3em;margin-right:1em;text-align:right;color:#a6a6a6;opacity:.6;user-select:none}</style>
<pre class="json-hl" style="background:#272822;color:#f8f8f2"><span class="p">{</span>
<span class="k">"id"</span><span class="p">:</span> <span class="n">7</span><span class="p">,</span>
<span class="k">"ok"</span><span class="p">:</span> <span class="b">true</span>
<span class="p">}</span></pre>
Each token is wrapped in a span with a short class: k for keys, s strings, n numbers, b booleans, u null and p punctuation.
Before you paste it into a site
The style block is written for a standalone page, so review it before embedding it in a larger one:
- Delete the
body{…}rule, or it will change the margin and background of the whole page. - The
pre{…}rule applies to everypreelement on the page. Change the selector topre.json-hlto limit it to the snippet. - Prefix the short class selectors with
.json-hl(for example.json-hl .k) if your site already uses classes namedk,sorn. - If you add several snippets to one page, include the style block once.
Platforms that strip <style> tags, such as some content management systems, will keep the background and text color because those are set inline on the pre element, but the token colors will be lost.
Preview and download
The Preview tab shows the highlighted JSON as a complete HTML page. With Preview active, Download saves that page as an .html file and Copy copies its full source, which is convenient for slides or for attaching a readable sample to an email.
Related tools
To highlight code in other languages, such as JavaScript, SQL or Python, use the general code highlighter. If you only need readable text without colors, the JSON pretty print tool is simpler. Highlighting runs in your browser, and your JSON is only sent to our server if you use Load URL or Save & Share.