Documentation

JsonDecode
in package
implements DecoderInterface

Decodes JSON data.

Tags
author

Sander Coolen sander@jibber.nl

Table of Contents

Interfaces

DecoderInterface

Constants

ASSOCIATIVE  = 'json_decode_associative'
True to return the result as an associative array, false for a nested stdClass hierarchy.
OPTIONS  = 'json_decode_options'
RECURSION_DEPTH  = 'json_decode_recursion_depth'
Specifies the recursion depth.

Properties

$serializer  : mixed
$defaultContext  : mixed

Methods

__construct()  : mixed
decode()  : mixed
Decodes data.
supportsDecoding()  : bool
Checks whether the deserializer can decode from given format.

Constants

ASSOCIATIVE

True to return the result as an associative array, false for a nested stdClass hierarchy.

public mixed ASSOCIATIVE = 'json_decode_associative'

OPTIONS

public mixed OPTIONS = 'json_decode_options'

RECURSION_DEPTH

Specifies the recursion depth.

public mixed RECURSION_DEPTH = 'json_decode_recursion_depth'

Properties

$defaultContext

private mixed $defaultContext = [self::ASSOCIATIVE => false, self::OPTIONS => 0, self::RECURSION_DEPTH => 512]

Methods

__construct()

public __construct([array<string|int, mixed> $defaultContext = [] ]) : mixed
Parameters
$defaultContext : array<string|int, mixed> = []

decode()

Decodes data.

public decode(string $data, string $format[, array<string|int, mixed> $context = [] ]) : mixed
Parameters
$data : string

The encoded JSON string to decode

$format : string

Must be set to JsonEncoder::FORMAT

$context : array<string|int, mixed> = []

An optional set of options for the JSON decoder; see below

The $context array is a simple key=>value array, with the following supported keys:

json_decode_associative: boolean If true, returns the object as an associative array. If false, returns the object as nested stdClass If not specified, this method will use the default set in JsonDecode::__construct

json_decode_recursion_depth: integer Specifies the maximum recursion depth If not specified, this method will use the default set in JsonDecode::__construct

json_decode_options: integer Specifies additional options as per documentation for json_decode

Tags
throws
NotEncodableValueException
see
https://php.net/json_decode

supportsDecoding()

Checks whether the deserializer can decode from given format.

public supportsDecoding(string $format) : bool
Parameters
$format : string

Format name

Return values
bool

        
On this page

Search results