✨ mirror_json
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