dynamo_json_decoder 1.0.6 copy "dynamo_json_decoder: ^1.0.6" to clipboard
dynamo_json_decoder: ^1.0.6 copied to clipboard

A Flutter project that decodes serialized JSON strings into Flutter collection objects.

dynamo_json_decoder #

A lightweight, high-performance utility for decoding serialized JSON text into Dart objects (Map or List). Designed for speed and ease of use in Flutter applications.

pub package License

🌟 Features #

  • Type-Safe Decoding: Easily convert raw JSON strings into Map<String, dynamic> or List<dynamic>.
  • Debug Logging: Integrated support for error tracking during the decoding process.
  • Zero Boilerplate: Static methods allow you to decode without instantiating complex classes.

📦 Installation #

Add the dependency to your pubspec.yaml:

dependencies:
  dynamo_json_decoder: ^1.0.0

Or run:

flutter pub add dynamo_json_decoder

🚀 Usage #

Import the library

import 'package:dynamo_json_decoder/dynamo_decoder.dart';

Simple Decoding Example

void fetchUser() async {
  String rawJson = '{"id": 1, "name": "John Doe"}';
  
  // Decode into a Map
  Map<String, dynamic> user = DynamoDecoder.decode(rawJson);
  
  print(user['name']); // Output: John Doe
}

Integration with HTTP

import 'package:http/http.dart' as http;

class CustomerDTO {
  int? customerID = 0;
  String? customerName = "";
  String? customerPhone = "";

  CustomerDTO({
    this.customerID,
    this.customerName,
    this.customerPhone,
  });

  CustomerDTO.init(){
    customerID = 0;
    customerName = "";
    customerPhone = "";
  }

  CustomerDTO fromMap(Map<String, dynamic> json) =>
      new CustomerDTO(
        customerID: json["customerID"],
        customerName: json["customerName"],
        customerPhone: json["customerPhone"],
      );
}

Future<CustomerDTO> getRemoteDataByID(int customerID) async {
  final response = await http.get(
     Uri.parse("https://api.example.com/data?customerID=${customerID}"));
  
  if (response.statusCode == 200) {
    // Automatically handles Maps
    return CustomerDTO.init().fromMap(DynamoDecoder.decode(response.body));
  }
}

Future<List<CustomerDTO>> getRemoteListData() async {
  List<CustomerDTO> customerList = [];
  
  final response = await http.get(
     Uri.parse("https://api.example.com/datalist"));
  
  if (response.statusCode == 200) {
    // Automatically handles Lists
    List<dynamic> entityMapList = DynamoDecoder.decode(response.body);
    entityMapList.forEach((element) {
      CustomerDTO customer = CustomerDTO.init().fromMap(element);
      customerList.add(customer);
    });
  }
  
  return customerList;
}

🛠️ Debug Mode #

You can pass a reviver function or enable debug logging to inspect the decoding process:

   Map<String, dynamic>? jsonObject = DynamoDecoder
      .decode(rawJson, debugMode: true, reviver: (k, v) {
      print('+++++++++++++++++++++++++++++ k, v ==>> ${k}, ${v}');
    });

📄 License #

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

🤝 Contributing #

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

2
likes
160
points
281
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter project that decodes serialized JSON strings into Flutter collection objects.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

cupertino_icons, flutter, logger

More

Packages that depend on dynamo_json_decoder