Lesson content
Read, practise, then check your understanding
PHP JSON functions require valid UTF-8. Use exceptions rather than silently accepting partial or ambiguous failure.
Practical example
<?php
$data = json_decode($body, true, 64, JSON_THROW_ON_ERROR);
if (!is_array($data) || !isset($data['name'])) throw new InvalidArgumentException();
$response = json_encode($data, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES);
Decoding syntax does not validate the application schema. Define required keys, types, ranges, unknown-key policy, and maximum depth/body size. Stable APIs should document number/date/null representation and avoid leaking internal object structures.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.