PHP Class Webmozart\Json\JsonDecoder

Since: 1.0
Author: Bernhard Schussek ([email protected])
Show file Open project: webmozart/json Class Usage Examples

Public Methods

Method Description
__construct ( JsonValidator $validator = null ) Creates a new decoder.
decode ( string $json, string | object $schema = null ) : mixed Decodes and validates a JSON string.
decodeFile ( string $path, string | object $schema = null ) : mixed Decodes and validates a JSON file.
getBigIntDecoding ( ) : integer Returns the decoding of big integers.
getMaxDepth ( ) : integer Returns the maximum recursion depth.
getObjectDecoding ( ) : integer Returns the decoding of JSON objects.
setBigIntDecoding ( integer $decoding ) Sets the decoding of big integers.
setMaxDepth ( integer $maxDepth ) Sets the maximum recursion depth.
setObjectDecoding ( integer $decoding ) Sets the decoding of JSON objects.

Private Methods

Method Description
decodeJson ( $json )

Method Details

__construct() public method

Creates a new decoder.
public __construct ( JsonValidator $validator = null )
$validator JsonValidator

decode() public method

If a schema is passed, the decoded object is validated against that schema. The schema may be passed as file path or as object returned from JsonDecoder::decodeFile($schemaFile). You can adjust the decoding with {@link setObjectDecoding()}, {@link setBigIntDecoding()} and {@link setMaxDepth()}. Schema validation is not supported when objects are decoded as associative arrays.
public decode ( string $json, string | object $schema = null ) : mixed
$json string The JSON string
$schema string | object The schema file or object
return mixed The decoded value

decodeFile() public method

Decodes and validates a JSON file.
See also: decode
public decodeFile ( string $path, string | object $schema = null ) : mixed
$path string The path to the JSON file
$schema string | object The schema file or object
return mixed The decoded file

getBigIntDecoding() public method

Returns the decoding of big integers.
public getBigIntDecoding ( ) : integer
return integer One of the constants {@link FLOAT} and {@link JSON_STRING}

getMaxDepth() public method

A depth of zero means that objects are not allowed. A depth of one means only one level of objects or arrays is allowed.
public getMaxDepth ( ) : integer
return integer The maximum recursion depth

getObjectDecoding() public method

Returns the decoding of JSON objects.
public getObjectDecoding ( ) : integer
return integer One of the constants {@link JSON_OBJECT} and {@link ASSOC_ARRAY}

setBigIntDecoding() public method

By default, big integers are decoded as floats.
public setBigIntDecoding ( integer $decoding )
$decoding integer One of the constants {@link FLOAT} and {@link JSON_STRING}

setMaxDepth() public method

If the depth is exceeded during decoding, an {@link DecodingnFailedException} will be thrown. A depth of zero means that objects are not allowed. A depth of one means only one level of objects or arrays is allowed.
public setMaxDepth ( integer $maxDepth )
$maxDepth integer The maximum recursion depth

setObjectDecoding() public method

By default, JSON objects are decoded as instances of {@link \stdClass}.
public setObjectDecoding ( integer $decoding )
$decoding integer One of the constants {@link JSON_OBJECT} and {@link ASSOC_ARRAY}