Skip to main content

Hujson grammar for tree-sitter

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())
    .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.0.0.tar.gz (9.9 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.0.0-cp38-abi3-win_amd64.whl (13.1 kB view details)

Uploaded CPython 3.8+Windows x86-64

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

Uploaded CPython 3.8+Windows x86

tree_sitter_hujson-1.0.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.0.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.0.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.0.0.tar.gz.

File metadata

  • Download URL: tree_sitter_hujson-1.0.0.tar.gz
  • Upload date:
  • Size: 9.9 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.0.0.tar.gz
Algorithm Hash digest
SHA256 a548cb5852aceeadaa34687ff7358ffa45d8fa5f0be684b3c64f5920957c64f8
MD5 74a4991a3da3f08a6ab6f43cfe37de64
BLAKE2b-256 37729da6900ce171720dfa6f3a2ba303935bead08825101793fe7af502c293db

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_hujson-1.0.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3c639b7ffde8a54b6cdcc2de50b8d25f8e8ea3cbfa54945b36d7b86fea161ea0
MD5 b72fc896ac260a4f1f70e5e342168fc0
BLAKE2b-256 5a073755486e7e58d60c41141e07be9dd8e10745bf92ede932f6b25a51f690da

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_hujson-1.0.0-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 58c40144bf4c5eac26e8bdd46a71b8708a545dffde4d68d68cafdcc384ffc1ac
MD5 a75bc293bf52422a304f59317b1b6e6b
BLAKE2b-256 78e9f18412d3ed5b4675b3af69dfbe7304036240c5f336d9a35be5cee634bf2e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_hujson-1.0.0-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7d87322c2125bc7cdab0bb13e67135dc3ec716e322719701e45d8ffff7737f7a
MD5 104aa985d5344f255f09c5bf60314676
BLAKE2b-256 0a2bcf6849bd94adfea829f38e5419776ba5470f9e3a639f44f4ee3e96a66465

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hujson-1.0.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.0.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.0.0-cp38-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 5e471ea6c49fb8c7467b32e7bae7495920eb4706f668cbd380906ca45656d146
MD5 e0f6571818694c295d0f7b1004dd3fb2
BLAKE2b-256 5d40118875139aa6581f2737b4b9bced76165c7376b2503b6606c2ac2158f340

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_hujson-1.0.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8e1fda086b9dd72de5d7cdb2c6b454037ab4f7d938ab1baec8f960216d09e30f
MD5 972c1a9c272a94364f701ae1b5e9a2ad
BLAKE2b-256 360138644a02b679a0b255c262e04a81a290550a7f47efb420c5204a9636ac3b

See more details on using hashes here.

Provenance

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