sokil/php-json-schema-defaults

Extracting default value from JSON Schema

Maintainers

Package info

github.com/sokil/php-json-schema-defaults

pkg:composer/sokil/php-json-schema-defaults

Statistics

Installs: 1 135

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2023-04-09 09:16 UTC

This package is auto-updated.

Last update: 2026-02-28 18:03:58 UTC


README

Coverage Status ci

Extracting default value from JSON Schema.

Supports drafts from v.7 or its dialects. Extractor trusts that passed schema is valid, so perform external validation for it.

Installation

composer req sokil/php-json-schema-defaults

Usage

$schema = '{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "array", 
    "items": {"type": "string", "default": "hello"}
}';

$extractor = new Extractor();
$defaultValue = $extractor->extract($schema); // ["hello"]

Console command

To get default value from schema in console use next bin:

./vendor/bin/json-schema-defaults ~/path/to/schema.json