New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

syntax-json

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

syntax-json

Minimal JSON syntax highlighter. Single-pass, zero dependencies, <1KB.

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

syntax-json

Minimal JSON syntax highlighter. Single-pass, zero dependencies, <1 KB.

  • < 600 bytes brotli, ~900 bytes minified
  • < 0.1 ms parse time — single-pass character scan
  • Zero dependencies
  • Zero DOM mutations — uses CSS Highlight API
  • Dark mode via prefers-color-scheme, Bootstrap, or CSS class
  • Auto-initializes — just add the script tag

Live Demo

Install

npm install syntax-json
import syntaxJSON from 'syntax-json';

CDN

<script src="https://cdn.jsdelivr.net/npm/syntax-json@1.0.1/dist/syntaxjson.min.js" crossorigin="anonymous"></script>

Usage

<pre><code class="json">{
  "name": "example",
  "value": 42,
  "active": true
}</code></pre>

<script src="https://cdn.jsdelivr.net/npm/syntax-json@1.0.1/dist/syntaxjson.min.js" crossorigin="anonymous"></script>

That's it. The script auto-highlights all <pre><code class="json"> elements on page load.

How It Works

  • Single-pass character scanner identifies strings, numbers, and keywords
  • Creates StaticRange objects for each token
  • Registers ranges with the CSS Highlight API (CSS.highlights)
  • Injects theme-aware styles via CSSStyleSheet

No innerHTML. No DOM mutations. No reflows.

Dark Mode

Auto-adapts via prefers-color-scheme. Force theme with:

<html data-bs-theme="dark">   <!-- Bootstrap 5.3 -->
<div class="dark">              <!-- CSS class -->

API

syntaxJSON(element)

Parse a <code> element and return highlight ranges.

const ranges = syntaxJSON(document.querySelector('code.json'));
// { s: [StaticRange...], n: [StaticRange...], k: [StaticRange...] }
KeyTokenLightDark
sStrings#22863a#a5d6ff
nNumbers#005cc5#79c0ff
kKeywords (true, false, null)#d73a49#ff7b72

License

MIT

Keywords

json

FAQs

Package last updated on 11 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts