talira

json_serializable

Generate JSON to and from code for annotated Dart classes

open sourceBSD-3-Clausefree

json_serializable generates the code that converts Dart and Flutter classes to and from JSON. You annotate a class with @JsonSerializable (from its companion package json_annotation), customize fields with @JsonKey and enums with @JsonEnum, and run build_runner to write the fromJson and toJson functions into a generated part file. It can also generate a JSON Schema for a class, and @JsonLiteral embeds a JSON file's contents as a Dart field. It lives in Google's GitHub organization, under a licence from the Dart project authors.

Problems it solves

  • stop hand-writing fromJson and toJson for my Flutter models
  • parse API responses into typed Dart classes
  • generate a JSON Schema from my Dart model classes
  • map snake_case JSON keys to camelCase Dart fields

Features

  • @JsonSerializable code generation for fromJson and toJson
  • @JsonKey field options
  • @JsonEnum for enums
  • JSON Schema generation
  • @JsonLiteral to embed JSON files