getdkan/rooted-json-data

Access and modify JSON-based data objects while enforcing JSON Schema

Installs: 130 909

Dependents: 1

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 0

Open Issues: 5

pkg:composer/getdkan/rooted-json-data

0.2.3 2025-03-13 19:25 UTC

README

Build status Maintainability Code Coverage

Access and modify JSON-based data objects while enforcing JSON Schema.

This library primarily wires together JsonPath-PHP and Opis JSON Schema, providing a JSON Object class that functions like a small internal service. Data can be added, retrieved and modified through a simple API, and any changes will immediately provoke a re-validation. Validation errors through exceptions with actionable messages.

Example:

$json = '{"number":3}';
$schema = '{"type": "object","properties": {"number":{ "type": "number" }}}';
$data = new RootedJsonData($json, $schema);
echo $data->{"$.number"}; // 3
echo $data->{"$[number]"}; // 3
echo "{$data}"; // {"number":3}
$data->{"$.number"} = "three"; // EXCEPTION