json method

TestRequest json(
  1. dynamic data
)

Set request body as JSON and automatically set Content-Type.

Automatically serializes the data to JSON and sets the appropriate Content-Type header. Accepts Maps, Lists, or any JSON-serializable data.

Example:

// Object data
testApp.post('/api/users')
  .json({'name': 'John', 'age': 30});

// Array data
testApp.post('/api/bulk')
  .json([{'id': 1}, {'id': 2}]);

data Data to serialize as JSON (Map, List, or primitive). Returns this request builder for method chaining.

Implementation

TestRequest json(dynamic data) {
  _body = data;
  _contentType = 'application/json';
  return this;
}