strict_json 2.0.6 icon indicating copy to clipboard operation
strict_json: ^2.0.6 copied to clipboard

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";

}
0
likes
120
pub points
51%
popularity

Publisher

unverified uploader

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

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

More

Packages that depend on strict_json