json_object_mapper
A simple and easy way to map Objects from JSON and to Map with support for Dart Native and Dart Web.
Main features:
- 
Works with simple Objects: no method implementation needed. 
- 
Compatible with Web (JS) and Native (VM) platforms. 
- 
No @annotations or code generation. 
- 
Only uses Mirrors if it's available in the platform (transparent load). 
JSONTransformer
You can use simple and easy JSONTransformer patterns to transform a JSON tree.
This helps to integrate JSON trees of 3rd part with your code, UI and Entities.
Usage
JSONObject
A simple JSON Object mapping example:
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() {
    return 'User{username: $username, email: $email}' ;
  }
}
main() {
  
      User user1 = User.fromFields("joe", "joe@mail.com") ;
      
      print("User[1]: $user1");      
      // User[1]: User{username: joe, email: joe@mail.com}
      print(user1.toJson());
      // {"username":"joe","email":"joe@mail.com"}
      User user2 = User.fromJson( '{"username":"joe2","email":"joe2@mail.com"}' ) ;
      
      print("User[2]: $user2");
      // User[2]: User{username: joe2, email: joe2@mail.com}
      
      print(user2.toJson());
      // {"username":"joe2","email":"joe2@mail.com"}
}
JSONTransformer
A simple JSON tree transformation example:
var json = {
        'result': [
          {'id': 1, 'name': 'a', 'group': 'x'},
          {'id': 2, 'name': 'b', 'group': 'y'},
          {'id': 3, 'name': 'c', 'group': 'z'},
        ]
      };
var transformer = JSONTransformer.parse('{result}.mapEntry(name,id).asMap()');
var json2 = transformer.transform(json);
/// json2 = {'a': 1, 'b': 2, 'c': 3}
JSONTransformer Operations
- {"$key"}: converts- nodeto a- $keyvalue of- node as Map.
- [$index]: converts- nodeto a- $indexvalue of- node as List.
- asMap(): converts- nodeto a- Map.
- asList(): converts- nodeto a- List.
- asString($delimiter): converts- nodeto a- String, using optional- $delimiterfor- node List.
- mapEntry($key,$value): converts- nodeor- node.entriesto a- MapEntry($key, $value).
- split($delimiter,$limit?): converts- nodeor- node.entriessplitting into a- Listof parts, using- $delimiter as RegExpand optional- $limit.
- uc(): converts- nodeor- node.entriesto an Upper Case- String.
- lc(): converts- nodeor- node.entriesto a Lower Case- String.
- trim(): converts- nodeor- node.entriesto a Trimmed- String.
- encodeJson($withIdent): converts- nodeencoding to a JSON- String, using optional- $withIdent as bool.
- decodeJson(): converts- nodeor- node.entriesdecoding to a JSON tree.
Features and bugs
Please file feature requests and bugs at the issue tracker.
Author
Graciliano M. Passos: gmpassos@GitHub.
License
Dart free & open-source license.