boundwize/jsonrecast
JsonRecast is an editable JSON AST for PHP with visitor traversal and formatting-preserving printing. Update JSON content programmatically while keeping indentation, spacing, and key order intact, so output differs only where you made changes—ideal for composer.json and config files.
composer.json, package.json, CI config, exported integration payloads, IaC parameter files — is a candidate. JsonRecast lets you do this in ~1 day instead of hand-rolling a tokenizer; the alternative (decode → mutate → json_encode) is 20 lines but destroys formatting and produces noisy diffs.*.json in this repo and rename key X, add field Y, or bump a version" without rewriting whitespace, key order, or indentation. This unlocks internal migration tooling and customer-facing upgrade assistants as a single investment.Adopt when most of these hold:
scripts" or "every string value under require" is awkward with json_decode + recursion and natural with a visitor.parse, visit, mutate, print) so replacing it later is a contained change.Look elsewhere — or use json_decode/json_encode — when:
json_decode. Don't put it on a hot request path; use it in CLI, jobs, and editors.To executives (one paragraph): A small, MIT-licensed PHP library that lets us edit JSON files programmatically while keeping the file byte-for-byte identical everywhere we didn't intentionally change. That means when our tool touches a customer's composer.json or config file, the pull request shows one changed line instead of a full-file rewrite — fewer support tickets, more trust, and a credible "safe, reviewable changes" story for any feature that writes into customer repos. Cost is essentially zero (MIT, no vendor lock-in) and it's quarantined behind our own interface, so the downside is limited to a few days of engineering if it doesn't work out. Risk to flag honestly: near-zero adoption today, so we'd be validating it ourselves and should treat it as a leaf dependency, not infrastructure.
To engineering (the ask): Spike it for two days against three real files from our repo — a composer.json, a CI workflow's JSON step, and a large exported payload. Success criteria: round-trip is a no-op on unmodified input, the visitor covers our "find and mutate nested keys" case without bespoke recursion, and PHP version/static-analysis constraints are compatible. Ship it behind a JsonEditor port with parse/mutate/print so a swap to a hand-rolled writer is a single-file change. Don't expose its AST types above the adapter, pin the version, and add a golden-file test suite that asserts byte-identical output on no-op edits.
How can I help you explore Laravel packages today?