vertilia/json-schema

JSON schema validator

v0.8 2021-05-02 22:31 UTC

This package is auto-updated.

Last update: 2024-04-29 05:11:16 UTC


README

A lightweight Draft 7 JSON Schema validator, according to Understanding JSON Schema.

Usage

<?php

$validator = new Vertilia\JsonSchema\JsonSchema('{
  "type": "array",
  "items": {"type": "number"}
}');

print_r($validator->isValid('[1, 2, 3]')); // true, array of numbers

print_r($validator->isValid('[1, 2, "3"]')); // false, array of numbers and a string

More examples available in /tests/.

Installation

cd /your/project/root/
composer require vertilia/json-schema