https://github.com/alash3al/dart-path-selector
extract values from Map/List using dot-seprated strings you don't have to cast multiple times to fetch a simple values, this is very useful while working with i.e json data
https://github.com/alash3al/dart-path-selector
dart flutter json selector
Last synced: about 1 year ago
JSON representation
extract values from Map/List using dot-seprated strings you don't have to cast multiple times to fetch a simple values, this is very useful while working with i.e json data
- Host: GitHub
- URL: https://github.com/alash3al/dart-path-selector
- Owner: alash3al
- License: mit
- Created: 2022-01-15T21:57:17.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-17T08:17:35.000Z (over 4 years ago)
- Last Synced: 2025-03-30T10:33:40.134Z (over 1 year ago)
- Topics: dart, flutter, json, selector
- Language: Dart
- Homepage: https://pub.dev/packages/path_selector
- Size: 9.77 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Simply extract required values from specific paths in a `Map` or a `List`, for now it works for strings keys
## Usage
```dart
import 'dart:convert';
import 'package:path_selector/path_selector.dart';
void main() {
final Map map = jsonDecode('''
{
"name": "Mohamed Al Ashaal",
"age": 28,
"contacts": {
"email": "m7medalash3al@gmail.com",
"facebook": "https://fb.me/alash3al",
"github": "https://github.com/alash3al"
},
"some.dot-key.included": "Works!",
"skills": [
{
"name": "PHP",
"rating": 0.9
},
{
"name": "Golang",
"rating": 0.9
},
{
"name": "Python",
"rating": 0.9
}
]
}
''');
// will print: Mohamed Al Ashaal
print(map.select("name"));
// will print: 20
print(map.select("age"));
// will print: m7medalash3al@gmail.com
print(map.select("contacts.email"));
// will print: [{name: PHP, rating: 0.9}, {name: Golang, rating: 0.9}, {name: Python, rating: 0.9}]
print(map.select("skills"));
// will print {name: PHP, rating: 0.9}
print(map.select("skills.#0"));
// will print: PHP
print(map.select("skills.#0.name"));
// will print: null
print(map.select("skills2.unknown_key.value"));
// will print: Works!
print(map.select("some\\.dot-key\\.included"));
}
```