final class Json

JSON encoder and decoder.

Constants

deprecated FORCE_ARRAY

deprecated PRETTY

deprecated ESCAPE_UNICODE

Methods

static string
encode(mixed $value, bool|int $pretty = false, bool $asciiSafe = false, bool $htmlSafe = false, bool $forceObjects = false)

Converts value to JSON format. Use $pretty for formatted output, $asciiSafe for ASCII-only output, $htmlSafe for HTML-safe output, and $forceObjects to encode non-associative arrays as objects.

static mixed
decode(string $json, bool|int $forceArrays = false)

Decodes a JSON string to a PHP value. Use $forceArrays to decode objects as arrays.

Details

at line 37
static string encode(mixed $value, bool|int $pretty = false, bool $asciiSafe = false, bool $htmlSafe = false, bool $forceObjects = false)

Converts value to JSON format. Use $pretty for formatted output, $asciiSafe for ASCII-only output, $htmlSafe for HTML-safe output, and $forceObjects to encode non-associative arrays as objects.

Parameters

mixed $value
bool|int $pretty
bool $asciiSafe
bool $htmlSafe
bool $forceObjects

Return Value

string

Exceptions

JsonException

at line 70
static mixed decode(string $json, bool|int $forceArrays = false)

Decodes a JSON string to a PHP value. Use $forceArrays to decode objects as arrays.

Parameters

string $json
bool|int $forceArrays

Return Value

mixed

Exceptions

JsonException

Traits

Prevents instantiation.