Skip to content

Encoding and Decoding

Adrian edited this page Apr 1, 2021 · 1 revision

decode( string $json ) : mixed

Decodes a json string, using the configured options. This wraps PHP's native json_decode() function.

parameters

  • string $json The json string to decode.

errors/exceptions

Throws PHP's native JsonException if decoding fails. See Handling Errors for more information.

return value

The decoded value on success.

encode( mixed $data [, bool $strict = true] ) : string

Encodes a value as json, using the configured options. This wraps PHP's native json_encode() function.

Additionally, encoding objects other than stdClass that do not inplement JsonSerializable will error unless $strict = false is passed.

parameters

  • mixed $data The value to encode.
  • bool $strict Should trying to encode non-json-able objects error?

errors/exceptions

Throws PHP's native JsonException if encoding fails. See Handling Errors for more information.

return value

The encoded json string on success.