flags); } if (false === $json) { throw new InvalidArgumentException( "JSON encoding failed for argument ".typeof($data). " \$data; ".json_last_error_msg()); } return (new Body)->append($json); } /** * @inheritdoc */ function decode(Body $body) : mixed { $data = json_decode($body); if (!isset($data) && json_last_error()) { throw new UnexpectedValueException("Could not decode JSON: ". json_last_error_msg()); } return $data; } }