Json
in package
Methods for handling JSON.
Table of Contents
Constants
- RECURSIVE_DEPTH : mixed = 512
Methods
- decode() : mixed
- Decode a JSON string, with objects converted into arrays
- encode() : string
- Encode a json array as a string.
- error() : array<string|int, mixed>
- Convert an error/exception into a JSON body.
Constants
RECURSIVE_DEPTH
public
mixed
RECURSIVE_DEPTH
= 512
Methods
decode()
Decode a JSON string, with objects converted into arrays
public
static decode(string $str[, int $flags = -1 ]) : mixed
Parameters
- $str : string
-
A JSON string. As per the spec, this should be UTF-8 encoded
- $flags : int = -1
-
Default:
JSON_INVALID_UTF8_SUBSTITUTEandJSON_THROW_ON_ERROR
Tags
Return values
mixed —The decoded value
encode()
Encode a json array as a string.
public
static encode(mixed $json[, bool|int $flags = -1 ]) : string
Parameters
- $json : mixed
- $flags : bool|int = -1
-
Applies pretty flags if
true, default:JSON_THROW_ON_ERROR
Tags
Return values
stringerror()
Convert an error/exception into a JSON body.
public
static error(Throwable $error[, bool $serialized = true ]) : array<string|int, mixed>
Parameters
- $error : Throwable
- $serialized : bool = true
-
use JsonSerializable if available.