json_query_dio

A thin Dio integration for json_query: pick and map fields straight off a Response, instead of wrapping response.data yourself.

final response = await dio.get('/user');

final user = response.map<User>(
  {
    'id': '.data.user.id',
    'name': '.data.user.profile.name',
    'package': '.data.user.subscription.package.name',
  },
  User.fromJson,
);

What this package is

Every method on json_query's JsonQuery class, mirrored as an extension on Response<dynamic>, applied to response.data:

response.get('.data.user.id');
response.pick({'id': '.data.user.id'});
response.pickList('.data.users', {'id': '.id'});
response.map<User>({'id': '.data.user.id'}, User.fromJson);
response.mapList<User>('.data.users', {'id': '.id'}, User.fromJson);

That's it. See the json_query README for the full query syntax and behavior — this package changes none of it, it just saves you writing JsonQuery(response.data) yourself.

What this package is not

  • It does not wrap or replace Dio's HTTP behavior. Requests, headers, interceptors, retries, cancellation, and DioExceptions are entirely Dio's — this package never touches them.
  • It does not add a request+project+map combinator (e.g. a dio.getMapped(...) that fires the request for you). Fire the request with dio as usual, then call these extensions on the resulting Response.
  • Query and mapping errors are exactly json_query's (JsonQuerySyntaxException, JsonQueryAccessException, re-exported here for convenience) — never mixed with HTTP errors.

Install

dependencies:
  json_query_dio: ^0.1.0

Libraries

json_query_dio
Thin json_query integration for Dio: pick and map fields directly off a Response, without an intermediate JsonQuery(response.data) step.