PHPackages                             dcblogdev/php-find-and-replace-json - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. dcblogdev/php-find-and-replace-json

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dcblogdev/php-find-and-replace-json
===================================

Find and replace keys or values in json or arrays

v1.1.2(3y ago)61.1k2MITPHP

Since Mar 7Pushed 3y ago2 watchersCompare

[ Source](https://github.com/dcblogdev/php-find-and-replace-json)[ Packagist](https://packagist.org/packages/dcblogdev/php-find-and-replace-json)[ Docs](https://github.com/dcblogdev/php-find-and-replace-json)[ GitHub Sponsors](https://github.com/dcblogdev)[ RSS](/packages/dcblogdev-php-find-and-replace-json/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d9143d7b9f0a7818fa372b266776686ef8e758e2102152ae9d5f752c06d0ca41/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6463626c6f676465762f7068702d66696e642d616e642d7265706c6163652d6a736f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dcblogdev/php-find-and-replace-json)[![Total Downloads](https://camo.githubusercontent.com/0c25d778314aa241b87c7ec42bdddef5c6fe464672a3e96a6181dc9e94120f62/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6463626c6f676465762f7068702d66696e642d616e642d7265706c6163652d6a736f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dcblogdev/php-find-and-replace-json)

[![Logo](https://repository-images.githubusercontent.com/245631268/aa9e9480-49c0-11eb-91c4-1bd9c9660361)](https://repository-images.githubusercontent.com/245631268/aa9e9480-49c0-11eb-91c4-1bd9c9660361)

Takes a JSON payload and replaces either a key or value from a provided array.

Install
-------

[](#install)

Install via Composer

```
composer require dcblogdev/php-find-and-replace-json
```

Usage
-----

[](#usage)

Provide a JSON array and an array containing values to replace.

Create an instance of FindAndReplaceJson call replace and pass in the JSON array and array of replacing values.

JSON is returned with the replaced values. Keys can also be replaced by specifying named keys in $replaces array.

```
$payload = json_encode([
    'name'   => 'Joe Bloggs',
    'age'   => 23,
    'location' => 'London',
]);

//let's replace the values for age and location
$replaces = [
    'age' => 45,
    'location' => "Manchester"
];

$runner = new FindAndReplaceJson();
return $runner->replace($payload, $replaces);
```

Result:

```
{
  "name": "Joe Bloggs",
  "age": "45",
  "location": "Manchester"
}
```

By default, JSON is expected but a normal array can be used by passing false as the third argument to FindAndReplaceJson. When the third argument (`$isJson`) is set to false FindAndReplaceJson expects an array and will return an array.

Contributing
------------

[](#contributing)

Contributions are welcome and will be fully credited.

Contributions are accepted via Pull Requests on [Github](https://github.com/dcblogdev/find-and-replace-json).

Pull Requests
-------------

[](#pull-requests)

- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept up-to-date.
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

Running Tests
-------------

[](#running-tests)

To run unit tests, simply execute the following command in your console:

```
vendor/bin/phpunit
```

Security
--------

[](#security)

If you discover any security related issues, please email  email instead of using the issue tracker.

License
-------

[](#license)

Please see the [license file](license.md) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 56.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~288 days

Total

4

Last Release

1399d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/39399156?v=4)[dcblog](/maintainers/dcblog)[@dcblog](https://github.com/dcblog)

---

Top Contributors

[![dcblogdev](https://avatars.githubusercontent.com/u/1018170?v=4)](https://github.com/dcblogdev "dcblogdev (9 commits)")[![ph4r5h4d](https://avatars.githubusercontent.com/u/2995107?v=4)](https://github.com/ph4r5h4d "ph4r5h4d (5 commits)")[![merloxx](https://avatars.githubusercontent.com/u/12734661?v=4)](https://github.com/merloxx "merloxx (2 commits)")

---

Tags

hacktoberfestphpjsonarray

### Embed Badge

![Health badge](/badges/dcblogdev-php-find-and-replace-json/health.svg)

```
[![Health](https://phpackages.com/badges/dcblogdev-php-find-and-replace-json/health.svg)](https://phpackages.com/packages/dcblogdev-php-find-and-replace-json)
```

###  Alternatives

[zakirullin/mess

Convenient array-related routine &amp; better type casting

21228.9k2](/packages/zakirullin-mess)[hi-folks/data-block

Data class for managing nested arrays and JSON data.

1472.2k](/packages/hi-folks-data-block)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
