npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

eslint-plugin-json-canonical

v2.1.3

Published

ESLint plugin enforcing RFC 8785 (JSON Canonicalization Scheme)

Readme

eslint-plugin-json-canonical

GitHub npm Release CI

An ESLint plugin for RFC 8785 (the JSON Canonicalization Scheme), built on @eslint/json.

npm downloads chart, log scale

Why

RFC 8785 defines a byte-for-byte canonical serialization of JSON: member ordering (§3.2.3), number formatting (§3.2.2.3), string escaping (§3.2.2.2), and whitespace (§3.2.1). This plugin enforces those facets as ESLint rules, autofixable, so a JSON file can be checked and corrected the same way any other source file is.

Member ordering (plain UTF-16 code-unit comparison) is exactly @eslint/json's own built-in json/sort-keys rule configured correctly -- no separate rule for it exists here. number-format and string-escaping are this plugin's own rules. Whitespace is where RFC 8785 and everyday JSON authoring genuinely disagree: the canonical form has none at all, collapsing a document to a single line, which is exactly wrong for a file someone is expected to keep reading and editing by hand. This plugin resolves that with three configs rather than picking one winner.

Getting started

pnpm add -D eslint-plugin-json-canonical @eslint/json
// eslint.config.ts
import json from '@eslint/json';
import jsonCanonical from 'eslint-plugin-json-canonical';
import { defineConfig } from 'eslint/config';

export default defineConfig([
  {
    files: ['**/*.json'],
    ignores: ['**/tsconfig*.json', '**/turbo.json', '**/package.json'],
    plugins: { json },
    extends: [jsonCanonical.configs.recommended],
  },
]);

The three configs

All three enable the same content-canonicalization rules (json/sort-keys, number-format, string-escaping); they differ only in whitespace/layout handling.

| Config | Content rules | Layout | | --- | --- | --- | | configs.recommended (default) | ✓ | Pretty-printed: 2-space indentation, one member/element per line, single trailing newline | | configs.contentOnly | ✓ | Untouched -- whatever whitespace the file already has | | configs.canonical | ✓ | Full RFC 8785 §3.2.1: no insignificant whitespace anywhere, collapsed to one line | | configs.contentOnlyJsonc | ✓ | Untouched; for json/jsonc files (comments, trailing commas) instead of plain JSON |

configs.recommended is the sensible everyday default: stable key order and canonical number/string formatting, in a layout that stays readable and diffable. Reach for configs.contentOnly if you already format JSON some other way (Prettier, a .editorconfig-driven formatter) and only want the content rules. Reach for configs.canonical for a genuine canonicalization pass -- hashing, signing, byte-for-byte comparison against another canonical producer -- where the output is never meant to be hand-edited again.

configs.recommended's pretty-printing is deliberately simple, not a prettier-compatible width-aware formatter: every non-empty object or array always breaks one member/element per line, however short, rather than packing short values onto one line the way prettier --write would. This is fully deterministic and needs no line-width bookkeeping, at the cost of sometimes producing a more broken-out document than Prettier would for the same input. If your project also runs Prettier over its JSON files, use configs.contentOnly instead so the two never disagree about layout.

pretty-format takes one option controlling indent width: 2 or 4 (that many literal spaces), 'tab' (one literal tab), or 'auto' (the default) -- which detects the indent a document already uses (the whitespace after its first genuinely-indented member) and re-applies that same unit at every level, falling back to two spaces only when there's nothing to detect (an already-compact document, or one whose only containers are empty). This means a project with an established 4-space or tab-indented JSON convention isn't silently reformatted to a hardcoded default the first time this rule activates:

rules: {
  'json-canonical/pretty-format': ['error', 4], // or 'tab', or 'auto' (the default)
}

None of the four configs touch **/tsconfig*.json, **/turbo.json, or **/package.json for you -- scope those yourself (see the example above and Notes on specific files below).

Rules

| Rule | Fixable | In recommended | In contentOnly | In canonical | | --- | --- | --- | --- | --- | | json/sort-keys (from @eslint/json, configured asc/caseSensitive: true/natural: false) | ✓ | ✓ | ✓ | ✓ | | number-format | ✓ | ✓ | ✓ | ✓ | | string-escaping | ✓ | ✓ | ✓ | ✓ | | pretty-format | ✓ | ✓ | | | | no-insignificant-whitespace | ✓ | | | ✓ |

  • number-format -- requires a JSON number literal's text to match ECMAScript's own Number::toString output (RFC 8785 §3.2.2.3). A value too large or small to represent exactly as an IEEE 754 double (1e400, say) is reported without a fix, since RFC 8785 canonicalization is not well-defined for it.
  • string-escaping -- requires a JSON string literal's escaping to match ECMA-262's Quote() operation (RFC 8785 §3.2.2.2), i.e. what JSON.stringify already produces for a plain string.
  • pretty-format -- see The three configs above. json/json only.
  • no-insignificant-whitespace -- the full RFC 8785 §3.2.1 whitespace facet: no space after :/,, no newlines, no indentation, nothing before the first token or after the last. json/json only -- see the rule's own source comment for why a JSONC counterpart will never exist (there is no well-defined answer for a comment's own attachment to a specific member once its surrounding whitespace is rewritten out from under it).

Notes on specific files

  • package.json -- its key order is a distinct, separately-optional convention (a fixed field-priority order such as name/version/description first, then alphabetical -- what syncpack format produces), not RFC 8785's plain alphabetical order. Scope this plugin away from package.json and use a dedicated tool for it (e.g. syncpack itself, or @exadev/eslint-config's own package-json-key-order rule) if you want its ordering enforced too.
  • tsconfig*.json / turbo.json -- these genuinely carry comments (TypeScript and Turborepo both accept them), so they need configs.contentOnlyJsonc under json/jsonc, not the plain-JSON configs, which fail to parse a comment at all.

Upgrading from v1

configs.recommended changed meaning in v2.0.0: it now includes pretty-format by default, where v1 left whitespace untouched. If you were relying on v1's configs.recommended behaviour, switch to configs.contentOnly, which is v1's configs.recommended unchanged.

Build, test, and lint

pnpm install
pnpm lint
pnpm typecheck
pnpm test           # 100% coverage required
pnpm test:mutation   # Stryker, 100% mutation score required
pnpm build

Each rule has a co-located *.test.ts. vitest.setup.ts wires RuleTester.describe/.it to Vitest's describe/it explicitly.

Release

Conventional commits drive semantic-release on every push to main: version bump, CHANGELOG.md, GitHub Release, and npm publish via OIDC trusted publishing (no stored token).

License

MIT