PHPackages                             boundwize/jsonrecast - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. boundwize/jsonrecast

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

boundwize/jsonrecast
====================

Editable JSON AST with visitor traversal and formatting-preserving printing.

1.0.3(2w ago)390.2k↑607.7%[1 PRs](https://github.com/boundwize/jsonrecast/pulls)1MITPHPPHP ^8.2CI passing

Since Jun 28Pushed 2w ago1 watchersCompare

[ Source](https://github.com/boundwize/jsonrecast)[ Packagist](https://packagist.org/packages/boundwize/jsonrecast)[ Docs](https://github.com/boundwize/jsonrecast)[ GitHub Sponsors](https://github.com/samsonasik)[ RSS](/packages/boundwize-jsonrecast/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (10)Dependencies (12)Versions (105)Used By (1)

JsonRecast
==========

[](#jsonrecast)

 [![JsonRecast Logo](docs/assets/jsonrecast-adaptive.svg)](docs/assets/jsonrecast-adaptive.svg)

 Editable JSON AST with visitor traversal and formatting-preserving printing.

[![Latest Version](https://camo.githubusercontent.com/98f611d982153fb4dc842fcc7e71e9a860043b2802dc6dff9f6a00986ad84ac1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f626f756e6477697a652f6a736f6e7265636173742e7376673f7374796c653d666c61742d737175617265)](https://github.com/boundwize/jsonrecast/releases)[![ci build](https://github.com/boundwize/jsonrecast/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/boundwize/jsonrecast/actions/workflows/ci.yml)[![Documentation](https://camo.githubusercontent.com/c67c5132a2e80493c519f164ac2f3fd940307f294f1eef43db91d13506342e1a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d47697448756225323050616765732d3039363964613f7374796c653d666c61742d737175617265)](https://boundwize.github.io/jsonrecast/)[![Code Coverage](https://camo.githubusercontent.com/13399da387007ed58b0e4aa316ef5ee7fa889f84acf97d822e6bb5cb3c0c36b0/68747470733a2f2f636f6465636f762e696f2f67682f626f756e6477697a652f6a736f6e7265636173742f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/boundwize/jsonrecast)[![PHPStan](https://camo.githubusercontent.com/fdcdf50c27377a0f41a7196eeaae8539c4684bfc8a1f9843fdac60fdbc53deab/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374796c652d6c6576656c2532306d61782d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265266c6162656c3d7068707374616e)](https://github.com/phpstan/phpstan)[![Downloads](https://camo.githubusercontent.com/4ec8903f5718f27abdf58ae2719edda82e29e4e7876502aab88053c66a5832e2/68747470733a2f2f706f7365722e707567782e6f72672f626f756e6477697a652f6a736f6e7265636173742f646f776e6c6f616473)](https://packagist.org/packages/boundwize/jsonrecast)

[![Windows](https://camo.githubusercontent.com/40d55ea84a66155f7e5a3ca552f53374c32693147bb1def55b3522fe5f4964c7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f57696e646f77732d737570706f727465642d3030373844363f6c6f676f3d77696e646f7773266c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d353535353535)](https://camo.githubusercontent.com/40d55ea84a66155f7e5a3ca552f53374c32693147bb1def55b3522fe5f4964c7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f57696e646f77732d737570706f727465642d3030373844363f6c6f676f3d77696e646f7773266c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d353535353535)[![macOS](https://camo.githubusercontent.com/87062865228d41f8646f09e2f5836456aaecf50f98a01a95ed649d9e9046e226/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61634f532d737570706f727465642d4330383446433f6c6f676f3d6170706c65266c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d353535353535)](https://camo.githubusercontent.com/87062865228d41f8646f09e2f5836456aaecf50f98a01a95ed649d9e9046e226/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61634f532d737570706f727465642d4330383446433f6c6f676f3d6170706c65266c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d353535353535)[![Linux](https://camo.githubusercontent.com/ecaba20632a2d08464c0ce7f3f974a13a937dd5acf6f9d0d1065325b78475899/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c696e75782d737570706f727465642d4643433632343f6c6f676f3d6c696e7578266c6f676f436f6c6f723d626c61636b266c6162656c436f6c6f723d353535353535)](https://camo.githubusercontent.com/ecaba20632a2d08464c0ce7f3f974a13a937dd5acf6f9d0d1065325b78475899/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c696e75782d737570706f727465642d4643433632343f6c6f676f3d6c696e7578266c6f676f436f6c6f723d626c61636b266c6162656c436f6c6f723d353535353535)

Edit JSON content without noisy diffs
-------------------------------------

[](#edit-json-content-without-noisy-diffs)

- Update JSON content programmatically and keep the original indentation, spacing, and key order intact.
- Transform documents with visitors, inspired by [nikic/PHP-Parser](https://github.com/nikic/PHP-Parser), with path awareness built in.
- The printed output differs from the input only where you made changes; nothing else is reformatted.

Installation
------------

[](#installation)

```
composer require boundwize/jsonrecast
```

Example
-------

[](#example)

Say we want to bump a dependency, add a new one, and remove an entry in `composer.json`. With JsonRecast, a single visitor does all three:

 [![Demo of JsonRecast bumping a dependency, adding a new one, and removing an entry in composer.json while preserving the original formatting, including non-standard alignment](docs/assets/jsonrecast-demo-adaptive.svg)](docs/assets/jsonrecast-demo-adaptive.svg)

```
