Laravel - HTTP Tests - Assert Json Structure

Assert that the response has a given JSON structure:

    
    $response->assertJsonStructure(array $structure);
	

For example, if the JSON response returned by your application contains the following data:

    
    {
        "user": {
            "name": "Steve Schoger"
        }
    }
	

You may assert that the JSON structure matches your expectations like so:

    
    $response->assertJsonStructure([
        'user' => [
            'name',
        ]
    ]);
	

Sometimes, JSON responses returned by your application may contain arrays of objects:

    
    {
        "user": [
            {
                "name": "Steve Schoger",
                "age": 55,
                "location": "Earth"
            },  
            {
                "name": "Mary Schoger",
                "age": 60,
                "location": "Earth"
            }
        ]
    }
	

In this situation, you may use the * character to assert against the structure of all of the objects in the array:

    
    $response->assertJsonStructure([
        'user' => [
            '*' => [
                 'name',
                 'age',
                 'location'
            ]
        ]
    ]);