json_resolve

Creator: coderz1093

Last updated:

0 purchases

json_resolve Image
json_resolve Images
Add to Cart

Description:

json resolve

json resolve #
Description #
json_resolve is a Dart library that helps accessing property in deep json object easily using keypath
Given the following deeply nested json
{
"movie": "isFun",
"earth": 199999,
"dc": [
{
"name": "Superman"
},
{
"name": "Flash"
},
{
"name": "Wonder Woman"
}
],
"marvel": [
{
"name": "Thor",
"weapon": "Mjolnir",
"appear": [
{
"year": 2011,
"title": "Thor"
},
{
"year": 2013,
"title": "The Dark World"
},
{
"year": 2017,
"title": "Ragnarok"
}
]
}
]
}
copied to clipboard
We can access using keypath. The library ensures safe type checking and casting, and use provided default value as last resort
final String byProperty = resolve(json: json, path: "movie", defaultValue: "error");
expect(byProperty, "isFun");

final int byInt = resolve(json: json, path: "earth", defaultValue: 0);
expect(byInt, 199999);

final String byIndex = resolve(json: json, path: "dc.2.name", defaultValue: "error");
expect(byIndex, "Wonder Woman");

final String byIndexThenProperty = resolve(json: json, path: "marvel.0.appear.1.title", defaultValue: "error");
expect(byIndexThenProperty, "The Dark World");
copied to clipboard
Installation #
First of all add the following dependencies to your pubspec.yaml:
dependencies:
json_resolve: ^1.0.0
copied to clipboard
Author #
Khoa Pham, [email protected]
License #
json_resolve is available under the MIT license. See the LICENSE file for more info.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.