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.

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.1.0.tar.gz (9.8 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.1.0-cp38-abi3-win_amd64.whl (13.2 kB view details)

Uploaded CPython 3.8+Windows x86-64

tree_sitter_hujson-1.1.0-cp38-abi3-win32.whl (13.0 kB view details)

Uploaded CPython 3.8+Windows x86

tree_sitter_hujson-1.1.0-cp38-abi3-musllinux_1_2_x86_64.whl (18.8 kB view details)

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

tree_sitter_hujson-1.1.0-cp38-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (18.9 kB view details)

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

tree_sitter_hujson-1.1.0-cp38-abi3-macosx_11_0_arm64.whl (11.5 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for tree_sitter_hujson-1.1.0.tar.gz
Algorithm Hash digest
SHA256 9035b1df7cf62efd7e8e236b60beda7cb9b6ef259e7053a47bba9cffeb9b0400
MD5 e9437e729cc3ab137d59c6bf0de5cbc4
BLAKE2b-256 3be350a2dc5dd9b42989d908c1be5806f1741a0ad2884c0a4491591824e6e773

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hujson-1.1.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.1.0-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_hujson-1.1.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 aeb77ebca384ec45a54022ddeaefcf862c8cb68c78f953a7d83db7d330aefb49
MD5 230dcee83ccd8183d9f9461409e804d0
BLAKE2b-256 9adea2f90f8f441944706e676c18a8c500b4102a75f8b22dc7c49849d4a30ad9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hujson-1.1.0-cp38-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.1.0-cp38-abi3-win32.whl.

File metadata

File hashes

Hashes for tree_sitter_hujson-1.1.0-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 43c46ffb2e6d34c55fe6d5d6c083a8ed31716854cb645c8ca8ccfa39671cb563
MD5 3ac6e4a765bdf0081032f65915c3caa0
BLAKE2b-256 0a41a721a0f3195c64cb0ef990876ab359da69b7cb4f3ed875507118be149ac4

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hujson-1.1.0-cp38-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.1.0-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_hujson-1.1.0-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d958e969f4e29b89121cb730d9ad5145bdae46a4e3342fa2e2b582f99ef6f82e
MD5 8a00b0bc2ca5be5f33f8f10af022595c
BLAKE2b-256 92c796455014a03c89c8289d66e955aba14c39f6c8b2d9961351288ed8203e3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hujson-1.1.0-cp38-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.1.0-cp38-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.1.0-cp38-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 1005f7f9e33c5395543530a7142b1d01a10183abc39525e5ee57971d0afe1db5
MD5 1cf1ceee1f55edba777ad4377498119f
BLAKE2b-256 28589b21e8dea395f859dda129ddc90a6347110545dbc9e8bfce210ad57a7ce4

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hujson-1.1.0-cp38-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.1.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_hujson-1.1.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7d0466aaecf529fe3ff47183ac2f188f0bb4b2562016903bbab509d02d401c1f
MD5 46d0a7e06198ae9c1914fb397e10dfba
BLAKE2b-256 4f73ab9a536b4d6b281f61c41c546b7f1f447d98f7f370f60f0d4c0ccbed1ea9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hujson-1.1.0-cp38-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