UTILITY

json_try_encode()

Encode JSON without throwing; return the supplied default on failure.

Signature

mixed json_try_encode(mixed $value, mixed $default = null, int $flags = 0)

Example

json_try_encode(['ok'=>true], null); // '{"ok":true}'

Available from: 1.5.0

Reference navigation

Previous: json_try_decode()

Next: kebab()

Back to utilities