parse static method

dynamic parse(
  1. Object input
)

Reads JSON from a String or from UTF-8 bytes.

Bytes are read in one pass. No full String is built. When you have both, prefer bytes. For example, use res.bodyBytes instead of res.body from an HTTP client.

The result is a Map, List, String, num, bool or null. JSON has no date type, so a date comes back as a String.

Throws a FormatException for bad JSON or bad UTF-8. Throws an ArgumentError for any other type of input.

Map<String, dynamic> a = JSON.parse('{"name":"dox"}');
Map<String, dynamic> b = JSON.parse(res.bodyBytes);

Implementation

static dynamic parse(Object input) {
  if (input is String) {
    return jsonDecode(input);
  }
  if (input is List<int>) {
    return _jsonUtf8Decoder.convert(input);
  }
  throw ArgumentError.value(
    input,
    'input',
    'must be a String or a List<int> of UTF-8 bytes',
  );
}