json_to_dto 0.1.0-beta json_to_dto: ^0.1.0-beta copied to clipboard
Convert JSON to Dart DTOs and back. Automate the model creation and the toJson and fromJson methods
example/json_to_dto_example.dart
import 'dart:convert';
import 'dart:io';
import 'package:json_to_dto/json_to_dto.dart';
const jsonString =
'{"name": "John", "age": 30, "isMarried": false, "height": 1.75,'
' "children": [{"name": "Alice", "children" : [{"name":"Tim"}]},'
' {"name": "Bob"}], "address": {"street": "Main Street", "number": 123}}';
void main() {
final jsonMap = json.decode(jsonString) as Map<String, dynamic>;
final code = jsonMap.toDtoDart('Person');
File('person.dart').writeAsStringSync(code);
}