Search packages, repositories and app categories

Package detailsv4.12.0

json_annotation

Classes and helper functions that support JSON code generation via the `json_serializable` package.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
15.3M
Likes
1.3K
Pub points
150

Install package

flutter pub add json_annotation

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The json_annotation package provides metadata annotations for Dart classes to enable JSON serialization and deserialization using the json_serializable code generator. It allows developers to define how classes map to JSON, supporting custom field names, required fields, and type conversions. This package is essential when working with JSON data in Flutter apps, especially when paired with json_serializable to generate boilerplate code automatically. It simplifies handling of complex data models and improves code maintainability.

Use cases

  • Serializing and deserializing Dart objects to/from JSON
  • Generating boilerplate code for JSON conversion
  • Handling nested or complex data structures
  • Integrating with APIs that return JSON
  • Supporting type-safe data models in Flutter apps

Key features

  • Annotations like @JsonSerializable and @JsonKey
  • Automatic code generation via build_runner
  • Support for custom field name mapping
  • Flexible null safety handling
  • Integration with json_serializable

Suitable for

  • Flutter developers working with JSON APIs
  • Projects requiring type-safe data models
  • Teams aiming to reduce manual serialization code
  • Apps with frequent API interactions
  • Developers using code generation workflows

Considerations

  • Requires build_runner and json_serializable to function
  • Needs regeneration after model changes
  • May increase build time slightly
  • Not suitable for runtime JSON parsing without generated code
  • Limited to compile-time code generation

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Dart CI

Provides Dart Build System builders for handling JSON.

json_serializable Pub Package

The core package providing Generators for JSON-specific tasks.

Import it into your pubspec dev_dependencies: section.

json_annotation Pub Package

The annotation package which has no dependencies.

Import it into your pubspec dependencies: section.

checked_yaml Pub Package

Generate more helpful exceptions when decoding YAML documents using package:json_serializable and package:yaml.

Import it into your pubspec dependencies: section.

example

An example showing how to set up and use json_serializable and json_annotation.

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package