Skip to main content

HuJSON (JWCC) grammar for tree-sitter — JSON with comments and trailing commas

Project description

tree-sitter-hujson

License: MIT SemVer tree-sitter ABI CI GitHub release npm PyPI crates.io

A tree-sitter grammar for HuJSON (Human JSON), also known as JWCC (JSON With Commas and Comments).

HuJSON is a strict superset of JSON that adds exactly two features:

  • C-style comments: line comments (//) and block comments (/* */)
  • Trailing commas: an optional trailing comma after the last element in arrays and objects

All valid JSON is valid HuJSON. HuJSON intentionally rejects every other extension (unquoted keys, hex literals, Infinity/NaN, single-quoted strings, and so on); object keys must be quoted strings, exactly as in standard JSON.

The grammar registers both the .hujson and .jwcc file extensions.

Installation

The grammar is published to npm, PyPI, and crates.io. Each package exposes the compiled language for use with that ecosystem's tree-sitter bindings.

Each example needs the tree-sitter runtime for that language alongside this grammar.

npm (Node.js)

npm install tree-sitter tree-sitter-hujson
const Parser = require("tree-sitter");
const HuJSON = require("tree-sitter-hujson");

const parser = new Parser();
parser.setLanguage(HuJSON);

PyPI (Python)

pip install "tree-sitter-hujson[core]"
import tree_sitter_hujson
from tree_sitter import Language, Parser

parser = Parser(Language(tree_sitter_hujson.language()))

crates.io (Rust)

cargo add tree-sitter tree-sitter-hujson
let mut parser = tree_sitter::Parser::new();
parser
    .set_language(&tree_sitter_hujson::LANGUAGE.into())
    .expect("loading HuJSON grammar");

Go, Swift, and C

These bindings ship in the repository and are consumed directly from the tagged source rather than a package registry.

Editor support

  • Zed: install the ggfevans/zed-hujson extension. This is the only editor integration maintained and tested here.
  • Other tree-sitter hosts (for example Neovim via nvim-treesitter, or Helix): this is a standard tree-sitter grammar and can be registered through each host's normal grammar mechanism.

Markdown code blocks fenced as ```hujson are highlighted in editors that resolve fence languages by name (verified in Zed). This works through the declared language scope and name; it needs no injections.scm on the grammar side, because the host Markdown grammar supplies the injection.

Provenance

Forked from tree-sitter/tree-sitter-json at commit 001c28d. The upstream grammar already supported comments, so HuJSON support needed only two changes:

  1. Trailing commas. The commaSep helper now allows an optional trailing comma:

    function commaSep1(rule) {
      return seq(rule, repeat(seq(",", rule)), optional(","));
    }
    
  2. String-only object keys. Upstream tree-sitter-json accepts numeric object keys (choice($.string, $.number)); HuJSON restricts keys to strings to match standard JSON, so bare numeric keys are parse errors. This tightened in v0.2.0.

AI disclosure

This project discloses AI involvement following the ai-disclosure convention. See AI_DISCLOSURE.md for the repo-level default, and per-file headers for any overrides.

Contributing

See CONTRIBUTING.md for development setup, the test suite, and the release process.

Licence

MIT, matching the upstream tree-sitter-json licence.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tree_sitter_hujson-1.2.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tree_sitter_hujson-1.2.0-cp310-abi3-win_amd64.whl (13.3 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_hujson-1.2.0-cp310-abi3-win32.whl (13.2 kB view details)

Uploaded CPython 3.10+Windows x86

tree_sitter_hujson-1.2.0-cp310-abi3-musllinux_1_2_x86_64.whl (19.1 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

tree_sitter_hujson-1.2.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (19.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

tree_sitter_hujson-1.2.0-cp310-abi3-macosx_11_0_arm64.whl (11.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file tree_sitter_hujson-1.2.0.tar.gz.

File metadata

  • Download URL: tree_sitter_hujson-1.2.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for tree_sitter_hujson-1.2.0.tar.gz
Algorithm Hash digest
SHA256 f2aefcdab5e8f061dc0700b85b52039eb95e3075be60d85569e207fb648c3818
MD5 ac8c342a9dc007c16f4a3322cc315a56
BLAKE2b-256 5e5dc08e5b69cd9dc5a7c10bb7987ea9a252b0c830515407144ff5ccf6fea0e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hujson-1.2.0.tar.gz:

Publisher: release.yml on ggfevans/tree-sitter-hujson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_hujson-1.2.0-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_hujson-1.2.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 12476923eff17f477374df827c96906bf1fc361c0c12d77ee2b702d8f57d78f0
MD5 277054f2ca6c5d475ae1314dd447badb
BLAKE2b-256 e6638c210682a8881e678bfb9684e672e3da7f84a1f702f990870382a8ab59ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hujson-1.2.0-cp310-abi3-win_amd64.whl:

Publisher: release.yml on ggfevans/tree-sitter-hujson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_hujson-1.2.0-cp310-abi3-win32.whl.

File metadata

File hashes

Hashes for tree_sitter_hujson-1.2.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 1226e07caee681342cb4716494514b9fa8f419b7ec9fa5855d8296dd9506fb4c
MD5 24abe81461908ac9ba21a70eda3a1788
BLAKE2b-256 a1403e9e8529eff62f0c0b1c60aaa01f7027f3f913a910c659a009f6bd4d6a1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hujson-1.2.0-cp310-abi3-win32.whl:

Publisher: release.yml on ggfevans/tree-sitter-hujson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_hujson-1.2.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_hujson-1.2.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d110393fb2ac265f7abecfc07e782ec9142982e721be3c15b7173e30f2d7df7d
MD5 43d9e7d4746e44fe4901ba7b4987ca10
BLAKE2b-256 e0375513abfbc4c4dcb2bd200c8495abb2a0ee4ff218ffee23f4d532922236bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hujson-1.2.0-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on ggfevans/tree-sitter-hujson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_hujson-1.2.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_hujson-1.2.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 cd17accc343a2fc6d4414f29b775eb0b271f5681f71169cfb0c6f161bcb6bcff
MD5 49ba7f6498e1e5367943d7067ec4d4f2
BLAKE2b-256 32f20bcde1ec75b9adf3cbdf27aa92e8fc2a0b2469a183b0aba7b27b9f0595a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hujson-1.2.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: release.yml on ggfevans/tree-sitter-hujson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_hujson-1.2.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_hujson-1.2.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1629bc03d00a50a5f38623afbd8b161836773fb0a7696511c46cc87bbebd9bab
MD5 ed5944bee4475f5a1d8ff223ec1cbbf9
BLAKE2b-256 d5281f8edda2ad1f87ceae2658098bc008ed7a1756c1083b3dbc6bf5a618432f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hujson-1.2.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on ggfevans/tree-sitter-hujson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page