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

outdated

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 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().getList("products").convertJsonMap((product) => Product.from(product)).toList();
  productList.forEach(print);

}

class Product {

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

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

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

}
2
likes
0
pub points
66%
popularity

Publisher

unverified uploader

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

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on strict_json