json_serializer 0.1.0 copy "json_serializer: ^0.1.0" to clipboard
json_serializer: ^0.1.0 copied to clipboard

Automatically convert JSON to dart objects in runtime without code generation.

example/json_serializer_example.dart

import 'package:json_serializer/json_serializer.dart';

class Person {
  final String name;
  final int age;
  final Address address;

  Person({required this.name, required this.age, required this.address});
}

class Address {
  final String street;
  final String city;

  Address({required this.street, required this.city});
}

main() {
  // Define user-defined types for successful deserialization
  JsonSerializer.options = JsonSerializerOptions(userTypes: [
    UserType<Person>(Person.new),
    UserType<Address>(Address.new),
  ]);

  var json =
      '{"name": "John", "age": 30, "address": {"street": "123 Main St", "city": "Sampletown"}}';

  var person = deserialize<Person>(json);

  print('Name: ${person.name}');
  print('Age: ${person.age}');
  print('Street: ${person.address.street}');
  print('City: ${person.address.city}');
}
10
likes
160
points
1.89k
downloads

Publisher

verified publisheredsonbonfim.com

Weekly Downloads

Automatically convert JSON to dart objects in runtime without code generation.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

fake_reflection

More

Packages that depend on json_serializer