tree-sitter-json
repository·master·Indexed 42 days ago
https://github.com/tree-sitter/tree-sitter-jsonA JSON grammar implementation for the tree-sitter incremental parsing library, version 0.24.8. It enables high-performance, syntax-aware analysis of JSON files by building a concrete syntax tree, with available Node.js bindings and integration support for ESLint via eslint-config-treesitter.
What's inside tree-sitter-json
- tree-sitter-json provides a JSON grammar for the tree-sitter incremental parsing library. It allows developers to perform high-performance, syntax-aware analysis of JSON files by building a concrete syntax tree.
Integrate tree-sitter-json with ESLint using eslint-config-treesitter
masterTo use the tree-sitter configurations in your ESLint setup, import
eslint-config-treesitterand spread its exported configuration array into youreslint.config.mjs(Flat Config) file. This allows you to apply tree-sitter-based linting rules to your project.import treesitter from 'eslint-config-treesitter'; export default [ ...treesitter, ];Use tree-sitter-json in Node.js
masterThe
tree-sitter-jsonpackage provides Node.js bindings for the JSON grammar. It can be required directly in a Node.js or Bun environment. The module exports the compiled Tree-sitter grammar object, which is used to parse JSON strings into syntax trees.If available, the module also exports
nodeTypeInfo, which contains metadata about the different node types defined in the JSON grammar (loaded fromsrc/node-types.json).const Parser = require('tree-sitter'); const JSON = require('tree-sitter-json'); const parser = new Parser(); parser.setLanguage(JSON); const sourceCode = '{"key": "value"}'; const tree = parser.parse(sourceCode); console.log(tree.to_string());Access JSON node type information via nodeTypeInfo
masterThe
tree-sitter-jsonmodule may export anodeTypeInfoproperty. This property contains a mapping of node type names to their respective metadata, which is useful for tools that need to understand the structure of the JSON grammar without manually inspecting the tree.const JSON = require('tree-sitter-json'); if (JSON.nodeTypeInfo) { console.log(JSON.nodeTypeInfo); }