json_to_dto 0.1.0-beta copy "json_to_dto: ^0.1.0-beta" to clipboard
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);
}
0
likes
160
pub points
0%
popularity

Publisher

verified publisherchristianfindlay.com

Convert JSON to Dart DTOs and back. Automate the model creation and the toJson and fromJson methods

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on json_to_dto