PHPackages                             estahn/phpunit-json-assertions - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. estahn/phpunit-json-assertions

ActiveLibrary[Testing &amp; Quality](/categories/testing)

estahn/phpunit-json-assertions
==============================

JSON assertions for PHPUnit (including JSON Schema)

v4.0.0(4y ago)36983.1k↓20%8[5 PRs](https://github.com/estahn/phpunit-json-assertions/pulls)7MITPHPPHP ^7.4|^8.0

Since Mar 16Pushed 1y ago3 watchersCompare

[ Source](https://github.com/estahn/phpunit-json-assertions)[ Packagist](https://packagist.org/packages/estahn/phpunit-json-assertions)[ Docs](https://github.com/estahn/phpunit-json-assertions)[ GitHub Sponsors](https://github.com/estahn)[ RSS](/packages/estahn-phpunit-json-assertions/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (5)Versions (15)Used By (7)

phpunit-json-assertions
=======================

[](#phpunit-json-assertions)

[![Latest Stable Version](https://camo.githubusercontent.com/9fa2d66229754d1aebdbe0d0f9d6011db11977e3ec1ce7bfafec665b46c7a6ac/68747470733a2f2f706f7365722e707567782e6f72672f65737461686e2f706870756e69742d6a736f6e2d617373657274696f6e732f76657273696f6e2e706e67)](https://packagist.org/packages/estahn/phpunit-json-assertions)[![Total Downloads](https://camo.githubusercontent.com/8d251f44b8dcafffad54acc801744ec4ec6d5d973f8d64e0b128ebe08e85ad2b/68747470733a2f2f706f7365722e707567782e6f72672f65737461686e2f706870756e69742d6a736f6e2d617373657274696f6e732f642f746f74616c2e706e67)](https://packagist.org/packages/estahn/phpunit-json-assertions)[![Test](https://github.com/estahn/phpunit-json-assertions/actions/workflows/build.yml/badge.svg)](https://github.com/estahn/phpunit-json-assertions/actions/workflows/build.yml)[![StyleCI](https://camo.githubusercontent.com/5ebfe0bf17ebf258239db857660b8292a75dd660ca828992bec3d7b3034b2859/68747470733a2f2f7374796c6563692e696f2f7265706f732f35333137373039362f736869656c64)](https://styleci.io/repos/53177096)[![Average time to resolve an issue](https://camo.githubusercontent.com/e423880fd88b110021487ba8e5917b723092e66bdb39841734f20efd68ec2f5b/687474703a2f2f697369746d61696e7461696e65642e636f6d2f62616467652f7265736f6c7574696f6e2f65737461686e2f706870756e69742d6a736f6e2d617373657274696f6e732e737667)](http://isitmaintained.com/project/estahn/phpunit-json-assertions "Average time to resolve an issue")[![Percentage of issues still open](https://camo.githubusercontent.com/3f8cb2fce5c23984d3786852c393f4cdd96ebebba476d7be145118ef605de71d/687474703a2f2f697369746d61696e7461696e65642e636f6d2f62616467652f6f70656e2f65737461686e2f706870756e69742d6a736f6e2d617373657274696f6e732e737667)](http://isitmaintained.com/project/estahn/phpunit-json-assertions "Percentage of issues still open")

JSON assertions for PHPUnit includes traits/methods to help validate your JSON data through various methods.

Features
--------

[](#features)

- Validate your JSON data via JSON Schema
    - describes your existing data format
    - clear, human- and machine-readable documentation
    - complete structural validation, useful for
        - automated testing
        - validating client-submitted data
    - See more details [here](http://json-schema.org/)
- Access JSON data through expressions (e.g. `foo.bar[3]`)
    - See more details [here](http://jmespath.org/examples.html)

Install
-------

[](#install)

```
$ composer require estahn/phpunit-json-assertions --dev

```

or in your `composer.json`:

```
{
    "require-dev": {
        "estahn/phpunit-json-assertions": "@stable"
    }
}
```

Asserts
-------

[](#asserts)

AssertDescriptionAvailable in[assertJsonMatchesSchema](https://github.com/estahn/phpunit-json-assertions/wiki/assertJsonMatchesSchema)Asserts that json content is valid according to the provided schema fileAllassertJsonMatchesSchemaStringAsserts that json content is valid according to the provided schema stringAllassertJsonValueEqualsAsserts if the value retrieved with the expression equals the expected valueAllassertJsonValueEqualsAsserts if the value retrieved with the expression equals the expected valueAllassertJsonResponseAsserts that a response is successful and of type jsonSymfonyUsage
-----

[](#usage)

You can either use the `trait` or `class` version.

### Trait

[](#trait)

```
