json_encode() converts PHP arrays/objects into JSON strings, while json_decode() parses JSON text back into PHP values, returning associative arrays when the second argument is true. JSON is the standard format for REST API payloads.
Errors during encoding/decoding can be inspected with json_last_error() or, in PHP 7.3+, by passing the JSON_THROW_ON_ERROR flag to throw a JsonException.