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

outdated

Strict working with json

strict_json #

The package provides strictly parse json data.

Example #


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

}

class Product {

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

  Product.fromJson(JsonMap json):
    id = json.intValue("id"),
    name = json.stringValue("name"),
    price = json.doubleValue("price"),
    stock = json.boolValueOr("stock", false),
    data = json.stringValueOr("data");

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

}```
2
likes
0
pub points
67%
popularity

Publisher

unverified uploader

Strict working with json

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on strict_json