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

outdated

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

strict_json #

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

Example #

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
67%
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