strict_json 2.2.1 copy "strict_json: ^2.2.1" to clipboard
strict_json: ^2.2.1 copied to clipboard

The package allows you to work with dynamic data in a strict form.

example/main.dart

import 'package:strict_json/strict_json.dart';

void main() {
  const String json = """{
    "products": [
      { "id": 1, "name": "Product 1", "price": 2.5, "data": "optional data" },
      { "id": 2, "name": "Product 2", "price": 3.0, "stock": true }
    ]
  }""";

  final productList = const Json(json).asMap().getJsonList("products").convertJsonMap((it) => Product(it)).toList();
  print(productList);
}

class Product {

  final int id;
  final String name;
  final double price;
  final String? data;
  final bool inStock;

  Product(JsonMap data):
    id = data.getInt("id"),
    name = data.getString("name"),
    price = data.getDouble("price"),
    inStock = data.getBool("stock", false),
    data = data.getStringOr("data");

  @override
  String toString() => "Product(id: $id, name: $name, price: $price, data: $data, inStock: $inStock)";

}
2
likes
130
pub points
65%
popularity

Publisher

unverified uploader

The package allows you to work with dynamic data in a strict form.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

More

Packages that depend on strict_json