final class Json

JSON encoder and decoder.

Constants

FORCE_ARRAY

PRETTY

ESCAPE_UNICODE

Methods

static string
encode(mixed $value, bool|int $pretty = false, bool $escapeUnicode = false)

Converts value to JSON format. Use $pretty for easier reading and clarity and $escapeUnicode for ASCII output.

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

Parses JSON to PHP value. Parameter $forceArray forces an array instead of an object as the return value.

static mixed
decodeFile(string $file, bool|int $forceArray = false)

Converts given JSON file to PHP value.

Details

at line 31
static string encode(mixed $value, bool|int $pretty = false, bool $escapeUnicode = false)

Converts value to JSON format. Use $pretty for easier reading and clarity and $escapeUnicode for ASCII output.

Parameters

mixed $value
bool|int $pretty
bool $escapeUnicode

Return Value

string

Exceptions

JsonException

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

Parses JSON to PHP value. Parameter $forceArray forces an array instead of an object as the return value.

Parameters

string $json
bool|int $forceArray

Return Value

mixed

Exceptions

JsonException

at line 80
static mixed decodeFile(string $file, bool|int $forceArray = false)

Converts given JSON file to PHP value.

Parameters

string $file
bool|int $forceArray

Return Value

mixed

Exceptions

JsonException

Traits

Static class.