tree-sitter-json

Fast, incremental JSON grammar for the Tree-sitter parsing framework.

Library
Cargo
v0.24.8
205stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
59/100Fair
Development Activity56
Maintenance28
Community72
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture82
Code Quality80
Innovation78
Learning Curve70

tree-sitter-json is the JSON grammar for Tree-sitter, the incremental parsing library that underpins syntax highlighting and code intelligence in modern editors. It compiles JSON source into a concrete syntax tree that can be re-parsed efficiently as the document changes, providing the structural foundation for highlighting, folding, navigation, and analysis. It is maintained under the core Tree-sitter organization and parses objects, arrays, strings, numbers, and literals into a concrete syntax tree.

The grammar ships with prebuilt bindings for Rust, C, Node.js, Python, Go, and Swift, so the same parser can be embedded in editors, language servers, and static-analysis pipelines regardless of host language.

What You Get

  • A complete JSON grammar (grammar.js) plus the generated C parser (src/parser.c) ready to compile
  • Rust bindings exposing the parser through the tree-sitter-language interface
  • Additional bindings for C, Node.js, Python, Go, and Swift from a single grammar source
  • Highlight and query files (queries/) for syntax highlighting and code navigation
  • A corpus test suite exercising the grammar’s constructs and error recovery

Common Use Cases

  • Powering syntax highlighting for JSON in code editors and terminal viewers
  • Building language servers and linters that need a structured view of JSON code
  • Enabling code folding, structural selection, and outline views for JSON files
  • Extracting or transforming JSON content programmatically via the syntax tree

Under The Hood

Architecture - The grammar is declared in grammar.js using Tree-sitter’s JavaScript DSL, defining JSON’s syntactic constructs with extras for whitespace and comments and, where needed, externals for context-sensitive tokens resolved by a custom scanner. The Tree-sitter CLI compiles this into a deterministic C parser (src/parser.c) that host bindings load at runtime. Tech Stack - The source of truth is the JavaScript grammar DSL; the generated parser is C. The Rust binding depends on tree-sitter-language and compiles the generated parser via a cc-based build script, exposing a LANGUAGE constant. Parallel bindings for C, Node.js, Python, Go, and Swift are generated from the same grammar. Code Quality - Correctness is anchored by Tree-sitter’s corpus test format (input snippets paired with expected S-expression trees) plus highlight fixtures, and CI runs on GitHub Actions. The generated parser is machine-produced and never hand-edited, so quality tracks the grammar definition and its tests. API Design - Integration is minimal: consumers pass the language’s exported LANGUAGE entry point to a Tree-sitter parser instance in their host language, so adding JSON parsing to an editor or tool takes only a few lines once the Tree-sitter runtime is present.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search