Json
in package
Json class.
Tags
Table of Contents
- TYPE_ARRAY = 1
- How objects should be encoded -- arrays or as StdClass. TYPE_ARRAY is 1 so that it is a boolean true value, allowing it to be used with ext/json's functions.
- TYPE_OBJECT = 0
- decode() : mixed
- Decodes the given $encodedValue string which is encoded in the JSON format.
- encode() : string
- Encode the mixed $valueToEncode into the JSON format.
- isEmpty() : bool
- Determine whether a variable is empty.
- isJson() : bool
- Check that a string is a valid JSON string.
- read() : array<string|int, mixed>
- Read json file to array.
- save() : bool|int
- Save json file from array.
Constants
TYPE_ARRAY
How objects should be encoded -- arrays or as StdClass. TYPE_ARRAY is 1 so that it is a boolean true value, allowing it to be used with ext/json's functions.
public
mixed
TYPE_ARRAY
= 1
TYPE_OBJECT
public
mixed
TYPE_OBJECT
= 0
Methods
decode()
Decodes the given $encodedValue string which is encoded in the JSON format.
public
static decode(string $encodedValue[, int $objectDecodeType = self::TYPE_ARRAY ]) : mixed
Uses ext/json's json_decode if available.
Parameters
- $encodedValue : string
-
Encoded in JSON format
- $objectDecodeType : int = self::TYPE_ARRAY
-
Optional; When TRUE, returned objects will be converted into associative arrays
Tags
Return values
mixed —encode()
Encode the mixed $valueToEncode into the JSON format.
public
static encode(mixed $valueToEncode, int $options) : string
Encodes using ext/json's json_encode() if available.
NOTE: Object should not contain cycles; the JSON format does not allow object reference.
NOTE: Only public variables will be encoded
Parameters
- $valueToEncode : mixed
- $options : int
-
Optional; whether or not to check for object recursion; off by default
Return values
string —JSON encoded object
isEmpty()
Determine whether a variable is empty.
public
static isEmpty(string|null $value) : bool
Parameters
- $value : string|null
Return values
bool —isJson()
Check that a string is a valid JSON string.
public
static isJson(string|null $value) : bool
Parameters
- $value : string|null
Return values
bool —read()
Read json file to array.
public
static read(string $path) : array<string|int, mixed>
Parameters
- $path : string
Tags
Return values
array<string|int, mixed> —save()
Save json file from array.
public
static save(string $path, array<string|int, mixed> $data) : bool|int
Parameters
- $path : string
- $data : array<string|int, mixed>