herrera-io / json
Encodes, decodes, and validates JSON data.
Installs: 4 467 371
Dependents: 9
Suggesters: 1
Security: 0
Stars: 51
Watchers: 1
Forks: 11
Open Issues: 0
Requires
- php: >=7.3
- ext-json: *
- justinrainbow/json-schema: ^5.1
- kherge/file-manager: ^2.6
- seld/jsonlint: ^1.5
This package is auto-updated.
Last update: 2020-01-31 14:57:04 UTC
README
JSON
A library for encoding, decoding, linting, and validating JSON data.
This library provides a simplified interface into existing functionality that
is provided by PHP's json
extension, justinrainbow/json-schema
, and also
seld/jsonlint
. The purpose is to make it easy to use while making it hard
to miss errors.
Usage
<?php use KHerGe\JSON\JSON; $json = new JSON(); // Decode JSON values. $decoded = $json->decode('{"test":123}'); // Decode JSON values in files. $decoded = $json->decodeFile('/path/to/file.json'); // Encode native values. $encoded = $json->encode(['test' => 123]); // Encode native values into files. $json->encodeFile(['test' => 123], '/path/to/file.json'); // Lint an encoded JSON value. $json->lint('{"test":}'); // Lint an encoded JSON value in a file. $json->lintFile('/path/to/file.json'); // Validate a decoded JSON value using a JSON schema. $json->validate( $json->decodeFile('/path/to/schema.json'), $decoded );
Documentation
The JSONInterface
interface is your
best resource. The JSON
class you will be using implements this interface
and contains all of the information you will need.
Requirements
- PHP 7.3+
- json
Installation
composer require kherge/json=^3
License
This library is released under the MIT and Apache 2.0 licenses.