This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is jsonpath-js, a TypeScript library implementing RFC 9535 JSONPath specification. The library provides a complete JSONPath query engine with 100% RFC compliance.
npm install- Install dependenciesnpm test- Run all tests (uses Vitest)npm run lint- Run Biome linternpm run build- Build the library using tsupnpm run build:parser- Regenerate parser from Peggy grammar (required after grammar changes)
npm test- Run all tests including RFC compliance tests- Tests are located in
tests/with RFC compliance tests intests/RFC9535/
git submodule update --init --recursive- Initialize git submodules (required for RFC compliance tests)
- Parse: JSONPath string → AST via Peggy-generated parser
- Execute: AST + JSON data → Node objects (value + path pairs)
- Return: Extract values or value+path pairs from final nodes
Grammar System (src/grammar/)
jsonpath.pegjs- Peggy grammar defining JSONPath syntaxjsonpath-js.js- Generated parser (auto-generated, don't edit directly)ast.d.ts- TypeScript definitions for AST nodes- Important: Always run
npm run build:parserafter modifying the grammar
Execution Engine
src/jsonpath-js.ts- MainJSONPathJSclass withfind()andpaths()methodssrc/parser.ts- Central execution engine that processes ASTsrc/parsers/- Specialized processors for different selector types:root.ts- Main segment processing logicfilter-selector.ts- Complex filtering with comparisonsarray-slice-selector.ts- Array slicing operationsfunction-extentions.ts- Built-in function execution
Type System
src/types/node.ts- Core Node abstraction (value + path)src/types/json.d.ts- Comprehensive JSON type definitions- All components use Node objects to maintain path tracking
Comparison System (src/comparator/)
- Type-specific comparators for all JSON types (Array, Boolean, Numeric, Object, String)
- Implements all JSONPath comparison operators (==, !=, <, <=, >, >=)
- Critical for filter expressions
Function System (src/functions/)
- Built-in JSONPath functions: count, length, match, search, value
- Strongly-typed function definitions and execution
- tsup: Modern bundler producing CommonJS and ESM outputs
- Peggy: Parser generator for JSONPath grammar
- Dual format: Both CJS and ESM with TypeScript definitions
- Modify
src/grammar/jsonpath.pegjs - Run
npm run build:parserto regenerate parser - Update
src/grammar/ast.d.tsif AST structure changes - Test thoroughly with RFC compliance suite
- Parser logic is in
src/parsers/- each selector type has its own file - All processing works with Node objects containing value and path
- Maintain path strings in JSONPath format (e.g.,
$['users'][0]['name'])
- Selectors: Add new selector types in
src/parsers/ - Functions: Add new functions in
src/functions/ - Comparators: Extend comparison logic in
src/comparator/
- RFC compliance tests in
tests/RFC9535/use official JSONPath test suite - Unit tests for each component in respective test files
- Always run full test suite before committing grammar changes
- Use Node objects for all data flow
- Type-safe AST processing throughout
- Maintain JSONPath specification compliance
- Parse-once, execute-many pattern for performance