com\setasign\SetaFramework\Helper

JsonHelper Class JsonHelper

File: /SetaFramework/src/Helper/JsonHelper.php

Class hierarchy

Summary

Constants

DEFAULT_ENCODING_OPTIONS

JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES = 79


Static Methods

decode()

public static JsonHelper::decode (
string $json,
bool $assoc = true,
int $depth = 512,
int $options = 0
): ?mixed

Decode the provided json.

Parameters
$json : string

The json string being decoded. This function only works with UTF-8 encoded strings. PHP implements a superset of JSON - it will also encode and decode scalar types and NULL. The JSON standard only supports these values when they are nested inside an array or an object.

$assoc : bool

When TRUE, returned objects will be converted into associative arrays.

$depth : int

User specified recursion depth.

$options : int

Bitmask of JSON decode options.

Exceptions

Throws \JsonException If unable to decode the $json.

See

encode()

public static JsonHelper::encode (
mixed $data,
int $encodingOptions = JsonHelper::DEFAULT_ENCODING_OPTIONS,
int $depth = 512
): string

Encode the provided data to JSON.

Default JSON encoding is performed with the following options, which produces RFC4627-compliant JSON, capable of embedding into HTML.

Parameters
$data : mixed
 
$encodingOptions : int

JSON_THROW_ON_ERROR is always included

$depth : int
 
Exceptions

Throws \JsonException If unable to encode the $data to JSON.