deep_pick 0.3.0 deep_pick: ^0.3.0 copied to clipboard
A library to access deep nested values inside of dart data structures, like returned from `dynamic jsonDecode(String source)`.
example/deep_pick_example.dart
// ignore_for_file: avoid_print
import 'dart:convert';
import 'package:deep_pick/deep_pick.dart';
void main() {
final json = jsonDecode('''
{
"shoes": [
{
"id": "421",
"name": "Nike Zoom Fly 3",
"tags": ["cool", "new"]
}
]
}
''');
final name = pick(json, 'shoes', 0, 'name').asString();
print(name); // Nike Zoom Fly 3
final manufacturer = pick(json, 'shoes', 0, 'manufacturer').asStringOrNull();
print(manufacturer); // null
final id = pick(json, 'shoes', 0, 'id').asInt();
print(id); // 421
final tags = pick(json, 'shoes', 0, 'tags').asListOrEmpty<String>();
print(tags); // [cool, new]
}