Support the ongoing development of Laravel.io →
Testing Laravel

Currently, I'm using assertJsonStructure in order to validate the structure, but it doesn't check the exact JSON structure, for example:

[

  {"id":1, "name": "Bueno Aires", "slug": "buenos-aires"},
  {"id":2, "name": "Neuquén", "slug": "neuquen"},
  {"id":3, "name": "Córdoba", "slug": "cordoba"}
]

Test results are:

assertJsonStructure([['id', 'name', 'slug']]);: true
assertJsonStructure([['id', 'name']]);: true

Test results expected:

assertJsonStructure([['id', 'name', 'slug']]);: true
assertJsonStructure([['id', 'name']]);: false

Is there some way to validate that?

Last updated 3 years ago.
0

You can consider using seeJsonSubset (more info here)

0

If you want to assert exactly the same json, checkout this package that add snapshot methods to PHPUnit: https://github.com/spatie/phpunit-snapshot-assertions

Last updated 7 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Bruno brunocascio Joined 3 Jul 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.