PHP code example of json-structure / sdk

1. Go to this page and download the library: Download json-structure/sdk 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/ */

    

json-structure / sdk example snippets




use JsonStructure\SchemaValidator;
use JsonStructure\InstanceValidator;

// Validate a schema
$schema = [
    '$schema' => 'https://json-structure.org/meta/core/v0/#',
    '$id' => 'https://example.com/person.struct.json',
    'name' => 'Person',
    'type' => 'object',
    'properties' => [
        'name' => ['type' => 'string'],
        'age' => ['type' => 'int32']
    ]
];

$schemaValidator = new SchemaValidator();
$schemaErrors = $schemaValidator->validate($schema);

// Validate an instance
$instance = ['name' => 'Alice', 'age' => 30];
$instanceValidator = new InstanceValidator($schema);
$instanceErrors = $instanceValidator->validate($instance);