- json_decode: documentation ( source)
- print_r: documentation ( source)
- printf: documentation ( source)
<?php
$json = 'invalid json test';
try {
$array = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
printf('Valid JSON output: %s', print_r($array, true));
} catch (\JsonException $exception) {
printf('Invalid JSON input: %s', print_r($exception, true));
}