json property

dynamic get json

Parse response body as JSON.

Automatically decodes the response body as JSON. Can return Maps, Lists, or primitive values depending on the JSON structure.

Example:

final data = response.json;
expect(data['id'], 123);
expect(data['items'], isList);

Throws FormatException if the response body is not valid JSON.

Implementation

dynamic get json {
  try {
    return jsonDecode(body);
  } catch (e) {
    throw FormatException('Response body is not valid JSON: $e');
  }
}