mirror_json 0.1.1
mirror_json: ^0.1.1

Dart native

A Dart library for parsing JSON objects using reflection (dart:mirrors). Does not support Flutter.

✨ mirror_json #

star this repo fork this repo Build Pub

A Dart library for parsing JSON objects using dart:mirrors.

Important: This library does not work in Flutter.

🔨 Installation #

Add mirror_json to your dependencies.

dependencies:
    ...
    mirror_json:

Now get the packages.

pub get

🔮 Getting started #

mirror_json uses a concept of Parsers. There are a bunch of parsers for simple types (int, double, String) already in the package, but in order to parse a class, you have to make a ClassParser instance.

import 'package:mirror_json/mirror_json.dart';

@JsonParseable()
class MyClass {
    ...
}

void main() {
    GlobalJsonParserInstance.initialize();
    var parser = ClassParser<MyClass>();

    // From json
    var myObject = Json.fromJson({...});

    // To json
    var json = Json.toJson(myObject);
}

Woah, what just happened?

First, we initialized mirror_json's main class, GlobalJsonParserInstance. This automatically adds parsers for simple types like int, double, List, etc. Then, we created a parser for MyClass. Now you can use the Json class to transform your JSON objects to MyClass instances or MyClass objects to JSON.

💡 Example #

See example under example folder.

📚 Docs #

See docs here

📭 Contact me #

E-Mail: kk.erzhan@gmail.com

0
likes
90
pub points
0%
popularity

A Dart library for parsing JSON objects using reflection (dart:mirrors). Does not support Flutter.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

kk.erzhan@gmail.com

License

BSD (LICENSE)

More

Packages that depend on mirror_json