Download the PHP package hgg/json without Composer
On this page you can find all versions of the php package hgg/json. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package json
Short Description Encode, decode, validate, handle errors (exceptions) and pretty print JSON
License MIT
Homepage http://github.com/hglattergotz/json
Informations about the package json
Json
Json is a collection of static methods to simplify working with JSON in PHP.
Features
- encode to JSON string with error handling
- decode from a string or file path containing valid JSON with error handling
- validate a JSON document against a JSON Schema
- pretty print a JSON string
Installation
The json-schema library version used here is currently a fork so you need to add the following to your composer.json file.
Dependencies
- JsonPretty A Json pretty printer by Cam Spiers
- JsonSchema A Json Schema validation library by Justin Rainbow
Usage
Encode
Decode from string
Decode the contents of $jsonString as an associative array.
Decode from file
Decode the contents of the file at $path as an associative array.
Pretty print
Note that the source can either be a JSON string or an array. The call below uses the default indentation of 2 spaces. To use a different indentation pass it as the second parameter.
Error handling
Instead of having to call and evaluating the integer response code the decode and encode methods throw an exception that contain the message as well as the code.
The code above example will output:
All versions of json with dependencies
camspiers/json-pretty Version v1.0.0
justinrainbow/json-schema Version *