Class JsonDecoder
Decodes JSON strings/files and validates against a JSON schema.
Methods summary
public
|
|
public
mixed
|
#
decode( string $json, string|object $schema = null )
Decodes and validates a JSON string.
|
public
mixed
|
#
decodeFile( string $file, string|object $schema = null )
Decodes and validates a JSON file.
Decodes and validates a JSON file.
Parameters
- $file
- The path to the JSON file.
- $schema
- The schema file or object.
Returns
mixed The decoded file.
Throws
See
|
public
integer
|
#
getMaxDepth( )
Returns the maximum recursion depth.
Returns the maximum recursion depth.
A depth of zero means that objects are not allowed. A depth of one means
only one level of objects or arrays is allowed.
Returns
integer The maximum recursion depth.
|
public
|
#
setMaxDepth( integer $maxDepth )
Sets the maximum recursion depth.
Sets the maximum recursion depth.
If the depth is exceeded during decoding, an 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.
Parameters
- $maxDepth
- The maximum recursion depth.
Throws
InvalidArgumentException If the depth is not an integer greater
than or equal to zero.
|
public
integer
|
#
getObjectDecoding( )
Returns the decoding of JSON objects.
Returns the decoding of JSON objects.
Returns
|
public
|
#
setObjectDecoding( integer $decoding )
Sets the decoding of JSON objects.
Sets the decoding of JSON objects.
By default, JSON objects are decoded as instances of \stdClass.
Parameters
Throws
InvalidArgumentException If the passed decoding is invalid.
|
public
integer
|
#
getBigIntDecoding( )
Returns the decoding of big integers.
Returns the decoding of big integers.
Returns
|
public
|
#
setBigIntDecoding( integer $decoding )
Sets the decoding of big integers.
Sets the decoding of big integers.
By default, big integers are decoded as floats.
Parameters
Throws
InvalidArgumentException If the passed decoding is invalid.
|
Constants summary
integer |
OBJECT
Decode a JSON value as PHP object.
Decode a JSON value as PHP object.
|
|
integer |
ASSOC_ARRAY
Decode a JSON value as associative array.
Decode a JSON value as associative array.
|
|
integer |
FLOAT
Decode a JSON value as float.
Decode a JSON value as float.
|
|
integer |
STRING
Decode a JSON value as string.
Decode a JSON value as string.
|
|