json static method

Response json(
  1. Object? data, {
  2. int status = 200,
  3. Headers? headers,
})

Implementation

static Response json(Object? data, {int status = 200, Headers? headers}) {
  final h = headers ?? Headers();
  if (!h.has('content-type')) {
    h.set('content-type', 'application/json; charset=utf-8');
  }
  final payload = Uint8List.fromList(utf8.encode(jsonEncode(data)));
  return Response(status, headers: h, body: Stream<List<int>>.value(payload));
}