Skip to content
pubscout

dart_json_mapper

2.2.20, released a year ago by edensapple.com

Annotate Dart objects to serialize and deserialize them from and to JSON.

WASM-ready
$ flutter pub add dart_json_mapper
Source repository

What it does

Allows developers to serialize and deserialize Dart objects to and from JSON using annotations. It generates a single mapping file for the entire project via code generation and avoids `dart:mirrors` for cross-platform compatibility.

AI-written summary of version 2.2.20, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want clean model classes free of manual JSON serialization logic.
  • You need advanced JSON mapping features like inheritance, polymorphism, and object cloning.
  • You prefer a single centralized mapping file over per-class generated files.

Skip it when

  • You prefer the standard Google-backed `json_serializable` approach with per-class generated files.
  • You want to avoid setting up `build_runner` code generation.

Strengths

  • Keeps model classes clean with no boilerplate serialization methods inside them.
  • Rich out-of-the-box features like polymorphism, object cloning, and case style conversion.
  • Generates a single centralized mapper file for the whole project.

Weaknesses

  • Requires running a code generator (`build_runner`) whenever model classes change.
  • Less common choice in the Dart ecosystem compared to `json_serializable`.

Setup

Kind
Pure Dart
Effort
Medium
Code generation
Yes (build_runner)
Direct dependencies
9

Requires adding `build_runner` to dev_dependencies and configuring `build.yaml` to run code generation.

import 'package:dart_json_mapper/dart_json_mapper.dart' show JsonMapper, jsonSerializable;
import 'main.mapper.g.dart' show initializeJsonMapper;

@jsonSerializable
class MyData {
  int a = 123;
  MyData(this.a);
}

void main() {
  initializeJsonMapper();
  print(JsonMapper.serialize(MyData(456)));
}

Alternatives

Packages that do the same job and could replace dart_json_mapper.

  • json_annotation

    It is the standard, widely adopted solution from the Dart team which generates per-class `*.g.dart` files.

  • built_value

    If you want immutable value types with built-in serialization and runtime validation.

  • freezed_annotation

    If you want union types, immutable classes, and pattern matching support along with JSON serialization.

Works with

Packages commonly used together with dart_json_mapper: ones it builds on, ones built on it, and its own family.