dart_jsona 0.0.4 copy "dart_jsona: ^0.0.4" to clipboard
dart_jsona: ^0.0.4 copied to clipboard

Deserialize or serialize JSON API document. Data formatter that creates simplified objects from JSON, creates JSON from the same simplified objects (in according with JSON API specification)

example/dart_jsona_example.dart

import 'package:dart_jsona/dart_jsona.dart';

void main() {
  Jsona jsona = new Jsona();

  Map<String, dynamic> body = {
    'data': {
      'type': 'town',
      'id': '123',
      'attributes': {
        'name': 'Barcelona',
      },
      'relationships': {
        'country': {
          'data': {
            'type': 'country',
            'id': '32',
          }
        }
      }
    },
    'included': [{
      'type': 'country',
      'id': '32',
      'attributes': {
        'name': 'Spain',
      }
    }]
  };

  final dynamic town = jsona.deserialize(body);

  print(town);
  /**
   * {
   *  type: town,
   *  id: 123,
   *  name: Barcelona,
   *  country: {
   *    type: country,
   *    id: 32, name: Spain
   *  },
   *  relationshipNames: [country]}
   */


  Map<String, Object> jsonBody = jsona.serialize(stuff: town, includeNames: ['country']);

  print(jsonBody);
  /**
   * {
   *   data: {
   *     id: 123,
   *     type: town,
   *     attributes: {
   *       name: Barcelona
   *     },
   *     relationships: {
   *       country: {
   *         data: {
   *           id: 32, type: country
   *         }
   *       }
   *     }
   *   },
   *   included: [{
   *     id: 32,
   *     type: country,
   *     attributes: {
   *       name: Spain
   *     }
   *   }]
   * }
   */
}
1
likes
25
points
16
downloads

Publisher

unverified uploader

Weekly Downloads

Deserialize or serialize JSON API document. Data formatter that creates simplified objects from JSON, creates JSON from the same simplified objects (in according with JSON API specification)

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on dart_jsona