json_annotation 0.2.9

  • README.md
  • Installing
  • Versions
  • 98

Defines the annotations used by json_serializable to create code for JSON serialization and deserialization.

See the example to understand how to configure your package.

Features and bugs

Please file feature requests and bugs at the issue tracker.


  • When FormatException is caught in "checked mode", use the message property when creating CheckedFromJsonException.


  • Added $checkKeys helper function and deprecated $checkAllowedKeys. Upgrading to the latest json_serializable and re-running your build will eliminate any @deprecated hints you see.

  • Added BadKeyException exception which is the abstract super class for MissingRequiredKeysException, UnrecognizedKeysException, and DisallowedNullValueException.

  • Added JsonKey.required field and an associated MissingRequiredKeysException that is thrown when required fields don't have corresponding keys in a source JSON map.

  • Added JsonKey.disallowNullValue field and an associated DisallowedNullValueException that is thrown when corresponding keys exist in a source JSON map, but their values are null.

  • Updated documentation of JsonSerializable.createToJson to include details of the new generate_to_json_function configuration option.


  • Small improvement to UnrecognizedKeysException.message output and documentation comments.


  • Added JsonSerializable.disallowUnrecognizedKeys.
    • Added a helper function to support this option. This function starts with a $ and should only be referenced by generated code. It is not meant for direct use.
    • Added UnrecognizedKeysException for reporting errors.


  • CheckedFromJsonException

    • Added a public constructor to support hand-written JSON decoding logic.
    • The message property is now String (instead of Object).
  • Added JsonKey.defaultValue.

  • Added helpers for deserialization of enum values. These functions starting with $ are referenced by generated code. They are not meant for direct use.


  • Added CheckedFromJsonException which is thrown by code generated when checked is enabled in json_serializable.

  • Added functions to support the checked generation option. These functions starting with $ are referenced by generated code. They are not meant for direct use.


  • Added fromJson and toJson fields to JsonKey class.


  • Added ignore field to JsonKey class annotation


  • Added a helper class – $JsonMapWrapper – and helper functions – $wrapMap, $wrapMapHandleNull, $wrapList, and $wrapListHandleNull – to support the useWrappers option added to JsonSerializableGenerator in v0.3.0 of package:json_serializable.


  • JsonSerializable class annotation
    • Added nullable field.
    • Fixed doc comment.


  • Moved annotation classes for JsonSerializable and JsonLiteral.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  json_annotation: "^0.2.9"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

      import 'package:json_annotation/json_annotation.dart';
Version Uploaded Documentation Archive
0.2.9 Jun 21, 2018 Go to the documentation of json_annotation 0.2.9 Download json_annotation 0.2.9 archive
0.2.8 Jun 8, 2018 Go to the documentation of json_annotation 0.2.8 Download json_annotation 0.2.8 archive
0.2.7+1 Jun 4, 2018 Go to the documentation of json_annotation 0.2.7+1 Download json_annotation 0.2.7+1 archive
0.2.7 Jun 1, 2018 Go to the documentation of json_annotation 0.2.7 Download json_annotation 0.2.7 archive
0.2.6 May 30, 2018 Go to the documentation of json_annotation 0.2.6 Download json_annotation 0.2.6 archive
0.2.5 May 22, 2018 Go to the documentation of json_annotation 0.2.5 Download json_annotation 0.2.5 archive
0.2.4 May 10, 2018 Go to the documentation of json_annotation 0.2.4 Download json_annotation 0.2.4 archive
0.2.3 Apr 3, 2018 Go to the documentation of json_annotation 0.2.3 Download json_annotation 0.2.3 archive
0.2.2 Dec 15, 2017 Go to the documentation of json_annotation 0.2.2 Download json_annotation 0.2.2 archive
0.2.1 Nov 2, 2017 Go to the documentation of json_annotation 0.2.1 Download json_annotation 0.2.1 archive

All 11 versions...


We analyzed this package on Jun 21, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
97 / 100
Code health derived from static analysis. [more]
100 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:json_annotation/json_annotation.dart.


  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use json_annotation.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.54.0 <2.0.0