A Simple lightweight JSON mapping utility.

How do I use it?

Download the dependency through Dart Pub Package manager. Add the following line to your pubspec.yaml dependencies:

json_mapper: "any"

Once you're done, get the package using pub get, then import it:

import 'package:json_mapper/json_mapper.dart' as jmap;

To serialize an object:

Use the serialize(Object obj) function. It takes any Dart object.

import 'package:json_mapper/json_mapper.dart' as jmap;

class Contact {
  int name;
  int mobile;
  int email;

void main() {
  Contact bob = new Contact()
    ..name = 'Bob Smith'
    ..mobile = '4161234567'
    ..email = [email protected]'
  String json = jmap.serialize(bob);

The output should be similar to:

Use the deserialize(String json, Type type) function. It takes a string, and any Dart Type, even your own.

{"name":"Bob Smith","mobile":"4161234567","email":"[email protected]"}

To deserialize a string back to an object


void main() {
  String json = '{"name":"Bob Smith","mobile":"4161234567","email":"[email protected]"}';
  Contact bobFromJson = jmap.deserialize(json, Contact);