json_object_mapper
2.0.1, released 6 years ago by an unverified publisher
Map plain Dart objects to and from JSON without annotations or code generation
What it does
Provides a lightweight JSONObject base class that can be extended to create POJOs. It also offers a JSONTransformer for transforming JSON trees using a simple DSL.
AI-written summary of version 2.0.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need quick, annotation-free JSON mapping for small to medium models
- You want to support both web and native without mirrors fallback
- You prefer a single dependency over code generation
Skip it when
- Your project already uses a codegen-based JSON library like json_serializable
- You need advanced features like nested custom converters or serialization hooks
Strengths
- Zero code generation, no build_runner
- Works on web and native out of the box
- Simple API, easy to learn
- Small dependency footprint
Weaknesses
- No support for custom converters or complex nested types
- Limited to simple POJOs, no immutability or validation
- No type safety for JSON keys
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
Add dependency to pubspec, import package, extend JSONObject
import 'package:json_object_mapper/json_object_mapper.dart';
class User extends JSONObject{String username;String email;User.fromFields(this.username,this.email);User.fromJson(String json){initializeFromJson(json);} @override String toString()=>"User{username: $username, email: $email}";}
void main(){var u=User.fromFields('joe','joe@mail.com');print(u.toJson());}Alternatives
Packages that do the same job and could replace json_object_mapper.
- json_annotation
Provides codegen with type safety and custom converters
84Compare - freezed_annotation
Offers immutable data classes with JSON support via codegen
78Compare
Works with
Packages commonly used together with json_object_mapper: ones it builds on, ones built on it, and its own family.