PHP code example of vrijdag / jsonvalidator

1. Go to this page and download the library: Download vrijdag/jsonvalidator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vrijdag / jsonvalidator example snippets


$json = json_decode($response_body, true));

if (is_array($json)) {
	foreach ($json as $property) {
		$info_i_need = $property['sub']['item'] ?? null;
		
		if (is_string($info_i_need)) {
			echo $info_i_need . "\n";
		}
	}
}

$schema = file_get_contents('schema.json');
$response = file_get_contents('response.json');

try {
    $jsonValidator = new JsonValidator\JsonValidator($schema, $response);
    $jsonValidator->validate();

    // This now exists, and is numeric
    echo $jsonValidator->getData()->query->results->channel->wind->direction . "\n";

    foreach ($jsonValidator->getData()->query->results->channel->item->forecast as $forecast) {
        // Each days high temperature
        echo $forecast->high . "\n";
    }
}
catch (JsonValidator\Exceptions\JsonValidatorException $e) {
    echo $e->getMessage();
}