This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
PHP 8.4+ port of Microsoft's node-jsonc-parser - a scanner and fault-tolerant parser for JSON with Comments (JSONC). Supports standard JSON plus // line comments and /* */ block comments.
# Run tests
composer test
# Run tests with coverage (minimum 80% required)
composer test-coverage
# Static analysis (PHPStan max level)
composer stan
# Format code (PSR-12 via Laravel Pint)
composer format
# Check formatting without changes
composer format-checkRun a single test file:
./vendor/bin/pest tests/Unit/Scanner/ScannerTest.phpRun tests matching a pattern:
./vendor/bin/pest --filter="parses objects"JsoncParser is the main facade providing static methods for all operations:
parse()- Direct evaluation to PHP arrays/objectsparseTree()- DOM-style AST withNodeobjectsvisit()- SAX-style streaming withJsonVisitorcallbacksformat()- Format with configurable optionsmodify()- Path-based insert/update/delete operationsapplyEdits()- Apply edit operations to text
src/
├── JsoncParser.php # Facade (public API)
├── Scanner/ # Tokenization
│ ├── Scanner # Character-by-character lexer
│ └── SyntaxKind # Token types enum (17 types)
├── Parser/ # Parsing logic
│ ├── Parser # Three parsing modes
│ ├── Node & NodeType # AST representation
│ └── JsonVisitor # Visitor interface
├── Format/ # Formatting
│ └── Formatter # Configurable pretty-printing
└── Edit/ # Modification
├── Editor # Insert/update/delete by path
└── RemoveMarker # Sentinel for deletion (since null is valid JSON)
- Scanner tokenizes input character-by-character, producing
SyntaxKindtokens - Parser consumes tokens in one of three modes:
- Direct evaluation: builds PHP arrays/objects via internal visitor
- Tree building: creates
NodeAST with parent/child references - Visitor pattern: triggers user-provided
JsonVisitorcallbacks
- Fault tolerance: Parser continues on errors, collecting them for reporting
RemoveMarker::instance()used for deletion sincenullis a valid JSON valueParseOptionscontrols:disallowComments,allowTrailingComma,allowEmptyContentEditoperations are offset-based; useapplyEdits()to apply them to text- Node navigation via
findNodeAtLocation(),getNodePath(),getNodeValue()
Uses Pest PHP with custom assertion helpers in tests/Pest.php:
assertKinds()- Verify scanner token sequenceassertValidParse()/assertInvalidParse()- Parse verificationassertTree()- AST structure verificationassertEdit()- Edit operation verification