# JSON5 Syntax Highlighting in Markdown and Docs | JSON5.dev


Source: https://json5.dev/tools/syntax-highlighting/

---

# JSON5 Highlighting in Markdown and Docs

Shiki and Prism know a `json5` language, highlight.js maps the name to its JSON grammar, and Pygments has a lexer.

This page shows what a `json5` code fence does in each highlighter, so you can pick the right label before you publish. We ran the same JSON5 sample through Shiki 4.6.0, Prism 1.30.0 and highlight.js 11.12.0 on 12-01-2026 and kept the real token output.

You will also find the evidence for a `json5` fence on GitHub, what Astro, Docusaurus, VitePress and MkDocs Material say about their highlighter, a fallback table for when `json5` is missing, and a copy-paste config for each tool we tested.

[Test Results](#results) [Fallback Table](#fallback) [Configs](#configs)

![A JSON5 code block in a Markdown page with colored comments, keys and numbers, beside a list of highlighter names](https://json5.dev/img/hero/tools-syntax-highlighting.png)

**TL;DR:** Write ` ```json5 ` first. In our tests Shiki 4.6.0 and Prism 1.30.0 (after loading its component) color comments, unquoted keys, single-quoted strings, hex numbers and signed numbers correctly, and highlight.js 11.12.0 accepts the label as an alias of its JSON grammar. Where a highlighter does not know the name, `js` degrades best in our tests. `json` and `jsonc` flag valid JSON5 as errors in Shiki.

[Test Sample](#sample) [Results](#results) [Fallback Table](#fallback) [GitHub](#github) [Docs Generators](#generators) [Configs](#configs) [FAQ](#faq)

![Test icon](https://json5.dev/images/icons/test.png)

## The Test Sample

A JSON5 highlighter has to get a short list of things right. Comments of both kinds, keys with no quotes, single-quoted strings, hex numbers, a number that starts with a dot, a number with a plus sign, and a [trailing comma](https://json5.dev/glossary/#trailing-comma). This sample contains all of them, and every result below comes from running it:

`{ // comment name: 'app', /* block */ ports: [8080, 0x1F, .5, +1,], "quoted": true, }`

Each test used the npm package named in the table below, installed in a clean folder on 12-01-2026. We read the [tokens](https://json5.dev/glossary/#punctuator) the library returned rather than judging a screenshot, so a result such as "tagged as a string" means the highlighter gave that token a string class or color.

![Code icon](https://json5.dev/images/icons/code.png)

## Which Highlighters Know JSON5

Highlighter

Version tested

Does `json5` exist?

Shiki

4.6.0

Yes. `'json5' in bundledLanguages` returned `true`, next to `json`, `jsonc` and `hjson`.

Prism

prismjs 1.30.0

Yes, as a component file, `components/prism-json5.js`. It must be loaded; it is not in the core.

highlight.js

11.12.0

As an alias only. `hljs.getLanguage('json').aliases` returned `['jsonc', 'json5']`, and there is no separate JSON5 grammar file.

Pygments

Docs page, not run

Yes. The lexer reference lists `pygments.lexers.json5.Json5Lexer`, short name `json5`, filename pattern `*.json5`, "Added in version 2.19."

prism-react-renderer

2.4.1

No. We listed the language names in its default bundle and `json5` was not among them; `json`, `javascript` and `js` were.

### Shiki 4.6.0

Shiki's `json5` grammar produced one token per literal and treated keys and single-quoted strings alike. With the `github-light` theme, `name` and `'app'` both came back with the string color, `#032F62`, and `0x1F`, `.5` and `+1` each came back as one number token. The comments came back in the comment color `#6A737D`.

The `json` and `jsonc` grammars returned the same output as each other for this sample, and both split valid JSON5 into pieces. `name` and `'app'` got `#B31D28`, which this theme uses for invalid text. `0x1F` became `0`, then `x` in the invalid color, then `1`, then `F` in the invalid color. `.5` and `+1` were split the same way. The `js` grammar gave no invalid tokens, colored the keys as properties, and returned `+` and `1` as two tokens.

### Prism 1.30.0

After loading the component, the `json5` grammar tokenized every item in the sample: both comments, `name` and `ports` as properties, `'app'` as a string, and `8080`, `0x1F`, `.5` and `+1` as numbers. The component file defines unquoted names as properties with the class alias `unquoted`, so a theme can style them differently.

The plain `json` grammar in the same package missed most of it. It found the comments and the quoted key, but gave no tokens to `name`, `ports`, `'app'` or `0x1F`, and returned `5` for `.5` and `1` for `+1` with the dot and the sign left outside the number. The `javascript` grammar handled everything, apart from splitting `+1` into an operator and a number.

### highlight.js 11.12.0

`hljs.highlight(code, { language: 'json5' })` ran without an error, because the JSON grammar declares `jsonc` and `json5` as aliases. In that output comments were comments, `'app'` was a string, and `0x1F`, `.5` and `+1` were numbers. The unquoted keys `name` and `ports` carried no class at all, while the quoted key `"quoted"` got the attribute class. So the keys of a typical JSON5 file look plain next to quoted ones.

Do not count on auto-detection. `highlightAuto` on this sample returned `pgsql`, which colored the word "comment" inside the comment as a keyword. The `javascript` grammar gave the keys the attribute class and highlighted everything else correctly.

![Compare icon](https://json5.dev/images/icons/compare.png)

## When `json5` Is Not Available

If your tool does not know the label, it either throws, prints plain text, or silently uses another grammar. These are the three labels people reach for, with what they got wrong in our sample:

Fence label

What it gets right

What it gets wrong

Verdict

`js` / `javascript`

Comments, unquoted keys, single quotes, hex, `.5` in Shiki, Prism and highlight.js

`+1` becomes an operator plus a number. Keys look like object properties, which they are. Anything JS-only that the sample does not contain would be colored as code.

Best fallback in our tests

`jsonc`

Comments

In Shiki, unquoted keys and single-quoted strings get the invalid color, and hex, leading-dot and plus-sign numbers are split into invalid pieces. highlight.js treats it as the same alias as `json5`.

Good only when the file has quoted keys

`json`

Quoted keys, strings, plain numbers

Same invalid output as `jsonc` in Shiki. In Prism, unquoted keys, single-quoted strings and hex get no token.

Worst for real JSON5

The practical rule is to use `js` only where `json5` is genuinely unavailable, and to fix the cause when you can. In Shiki the fix is nothing, because the grammar is bundled. In Prism it is one loader line. Shiki also throws on a label it does not have: our call with a made-up language raised the error ``Language `nolang` is not included in this bundle``. That is useful, since a typo in a label fails the build instead of shipping unhighlighted text.

These results are about colors in a snippet. They do not tell you whether the code you show is valid. Check that separately with the [online validator](https://json5.dev/tools/online-validator/), and keep the file the sample came from, not a screenshot of it.

![Code file icon](https://json5.dev/images/icons/code-file.png)

## GitHub and linguist

GitHub's language list lives in the open-source linguist project, in `lib/linguist/languages.yml`. We opened the file on 12-01-2026. It has a language named JSON5, and this is its whole entry:

`JSON5: type: data color: "#267CB9" extensions: - ".json5" tm_scope: source.js ace_mode: json5 codemirror_mode: javascript codemirror_mime_type: application/json language_id: 175`

What the entry shows: the type is `data`, the only file extension is `.json5`, and the `tm_scope` is `source.js`, the JavaScript grammar scope. It has no `aliases` and no `filenames` list. By comparison, the "JSON with Comments" entry in the same file has the alias `jsonc` and the scope `source.json.comments`, with filenames such as `tsconfig.json`.

That is the evidence for using a `json5` fence on GitHub: the language exists in linguist, and a file ending in `.json5` is classed as it. We did not render a Markdown file on GitHub, so this page makes no claim about how a fenced block looks there. Open a gist and look if the exact colors matter to you.

![Document icon](https://json5.dev/images/icons/document.png)

## Docs Generators

A docs site does not choose a highlighter per page; the generator picks it. We opened each generator's documentation on 12-01-2026 and list only what it says. The right-hand column joins that to the tests above.

Generator

What its docs say

What that means for `json5`

Astro

Markdown code blocks are styled by Shiki by default, preconfigured with the `github-dark` theme.

Shiki has `json5` in our test. The Shiki version inside your Astro release may differ from 4.6.0, so check the lock file.

Docusaurus

Syntax highlighting is powered by Prism React Renderer, with a subset of languages by default. More are added with `additionalLanguages` under `themeConfig.prism`.

Add `'json5'` to that list, since the Prism package has the component. We did not run a Docusaurus build, and prism-react-renderer's own default bundle had no `json5`.

VitePress

Uses Shiki to highlight code blocks and points to the Shiki language list.

Same as Astro: Shiki's `json5` applies. VitePress's page does not name the version.

MkDocs Material

`pymdownx.highlight` does the highlighting at build time, and `use_pygments` defaults to `true`.

Pygments has a `json5` lexer, added in 2.19 per the lexer reference. Check the Pygments version your build installs.

If a build uses an older Pygments than 2.19, it would not have the `json5` lexer according to those same docs, so pin or upgrade it before relying on the label.

![Settings icon](https://json5.dev/images/icons/settings.png)

## Copy-Paste Configs

### Shiki with markdown-it

We ran this with Shiki 4.6.0, `@shikijs/markdown-it` 4.6.0 and markdown-it 15.0.3. A `json5` fence rendered as a `pre` with the classes `shiki shiki-themes github-light github-dark` and the dark colors in CSS variables.

`import MarkdownIt from 'markdown-it'; import Shiki from '@shikijs/markdown-it'; const md = MarkdownIt(); md.use(await Shiki({ themes: { light: 'github-light', dark: 'github-dark' }, })); console.log(md.render('```json5\n{ a: 1, // c\n}\n```'));`

### Astro and VitePress

No language setting is needed for `json5` if the bundled Shiki includes it. The Astro docs show the theme setting like this:

`// astro.config.mjs import { defineConfig } from 'astro/config'; export default defineConfig({ markdown: { shikiConfig: { themes: { light: 'github-light', dark: 'github-dark' }, }, }, });`

### Prism (Node)

Tested with prismjs 1.30.0. Without the loader line, `Prism.languages.json5` is undefined.

`const Prism = require('prismjs'); const loadLanguages = require('prismjs/components/'); loadLanguages(['json5']); const html = Prism.highlight(source, Prism.languages.json5, 'json5');`

### Docusaurus

The shape comes from the Docusaurus docs, with `json5` in place of their PowerShell example. We did not build a Docusaurus site, so confirm that it renders before you ship.

`// docusaurus.config.js export default { themeConfig: { prism: { additionalLanguages: ['json5'], }, }, };`

### highlight.js

Tested with highlight.js 11.12.0. The name resolves through the alias list of the JSON grammar.

`const hljs = require('highlight.js'); const html = hljs.highlight(source, { language: 'json5' }).value;`

### MkDocs Material

The snippet is the one in the Material documentation. Use ` ```json5 ` in the page, and make sure the installed Pygments is 2.19 or newer.

`markdown_extensions: - pymdownx.highlight: use_pygments: true - pymdownx.superfences`

## JSON5 Highlighting: Common Questions

### Which fence label should I write?

`json5`. It works in Shiki, Prism (loaded), highlight.js (as an alias) and Pygments 2.19 and later, and linguist has a language of that name.

### Why is my valid JSON5 red in a `json` block?

The JSON grammar flags what strict JSON forbids. In Shiki 4.6.0, unquoted keys, single quotes, hex and leading-dot numbers all got the invalid color. Switch the label to `json5`.

### Is `jsonc` good enough?

Only if your file has quoted keys and double-quoted strings. For comments alone it is fine; for the rest of JSON5 it matched `json` in Shiki.

### Does a fence label change how a file is parsed?

No. The label only picks colors. To check that the text is valid, run it through a parser or the [online validator](https://json5.dev/tools/online-validator/).

### What about an editor inside a web page?

Showing code and editing it are different jobs. See the guide to [CodeMirror and Monaco](https://json5.dev/tools/codemirror-monaco/) for editors you embed.

### Where do editors get their colors?

Editors ship their own grammars. The [VS Code guide](https://json5.dev/tools/vscode/) covers that side.

## See Also

[![Editor icon](https://json5.dev/images/icons/editor.png)

### CodeMirror and Monaco

Embed an editor in a web app

](https://json5.dev/tools/codemirror-monaco/)[![Code icon](https://json5.dev/images/icons/code.png)

### VS Code

Editor support for JSON5

](https://json5.dev/tools/vscode/)[![Checklist icon](https://json5.dev/images/icons/checklist.png)

### Online Validator

Check the snippet you publish

](https://json5.dev/tools/online-validator/)

## Sources

(9)

1.  [github-linguist: languages.yml (JSON5, JSON, JSON with Comments entries)](https://github.com/github-linguist/linguist/blob/main/lib/linguist/languages.yml)
2.  [Pygments: available lexers (Json5Lexer, JsonLexer)](https://pygments.org/docs/lexers/)
3.  [shiki on npm (4.6.0)](https://www.npmjs.com/package/shiki) and [Shiki: languages](https://shiki.style/languages)
4.  [prismjs on npm (1.30.0)](https://www.npmjs.com/package/prismjs)
5.  [highlight.js on npm (11.12.0)](https://www.npmjs.com/package/highlight.js)
6.  [Astro docs: syntax highlighting](https://docs.astro.build/en/guides/syntax-highlighting/)
7.  [Docusaurus docs: code blocks](https://docusaurus.io/docs/markdown-features/code-blocks)
8.  [VitePress docs: Markdown extensions](https://vitepress.dev/guide/markdown)
9.  [MkDocs Material docs: Python Markdown extensions (Highlight)](https://squidfunk.github.io/mkdocs-material/setup/extensions/python-markdown-extensions/)

Last reviewed: December 1, 2026.

## Check the Snippet Before You Publish

Colors only show what a highlighter thinks. Paste the sample into the validator to see whether it parses.

[Online Validator](https://json5.dev/tools/online-validator/) [All Tools](https://json5.dev/tools/)
