PHP 8 · Strings and arrays

Encode and decode JSON

Convert to and from JSON, throwing exceptions on errors.

$json = json_encode($data, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
$data = json_decode($json, true, flags: JSON_THROW_ON_ERROR);

Official PHP 8 documentation

More strings and arrays commands

All strings and arrays commands · PHP 8 cheatsheet

Was this page helpful?