A simple PHP library for reading, formatting and getting values of a JSON data.
Install via Composer:
composer require iamjohndev/json-reform:dev-main
use iamjohndev\JSONReform;
// Read JSON data from a string
$json = '{"name": "John", "age": 30}';
$reader = new JSONReform($json);
// Get a value from the JSON data
$name = $reader->getValue('name'); // "John"
// Format the JSON data
$prettyJson = $reader->format('pretty'); // "{\n "name": "John",\n "age": 30\n}"
// Read JSON data from a file
$reader = JSONReform::fromFile('data.json');
// Get a nested value from the JSON data
$value = $reader->getValue('data.persons.0.name'); // "John"JSONReform::__construct(string $json)
// Creates a new JSONReform instance from a JSON string.
JSONReform::fromFile(string $path)
// Creates a new JSONReform instance from a JSON file.
JSONReform::getValue(string $path, mixed $default = null): mixed
// Gets the value at the specified path in the JSON data.
JsonReform::fromHTTPRequestBody();
// Creates a new JsonReform instance from an HTTP Request Body
JSONReform::format(string $format = 'json'): string
// Returns the JSON string in the specified format.