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 require boundwize/jsonrecast
composer.json, package.json, or a tool-specific config file.
json_decode/JsonResponse for runtime JSON, and JsonRecast for developer tooling and carefully controlled file edits.Parse → transform → print → compare → write
// Illustrative shape; adapt class names to the package API.
$original = File::get(base_path('composer.json'));
$document = $parser->parse($original);
$document->accept(new SetScript('post-install-cmd', 'php artisan migrate --force'));
$updated = $printer->print($document);
if ($updated !== $original) {
// write atomically
}
Wrap the package in a Laravel service/action
transform(string $json, Visitor $visitor): string.Use visitors for repeatable transformations
Build Artisan commands with operational safety
--dry-run.json_decode(..., true) before replacing the file.base_path(), config_path(), or explicit paths rather than relative paths.Use in CI/maintenance tooling
Test round-trips with fixtures
tests/fixtures.composer.json, follow writes with composer validate. For package.json, validate with the relevant Node tooling if available.Formatting preservation is not the same as “any edit preserves everything”
JSON strictness matters
composer.json, and package.json should remain strict JSON.Key order and duplicate keys
Numeric precision
Encoding and line endings
Avoid unnecessary writes
Atomic writes and concurrency
composer.json, where a bad write can break installs.Visitor mutation semantics
Laravel config cache
php artisan config:clear or document the required cache refresh.Package maturity risk
composer.json, wrap usage behind your own service, and keep a fallback path using json_decode/json_encode when formatting preservation is not required.How can I help you explore Laravel packages today?