Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ayan-b/json_traverse
:palm_tree: Traverse a deeply nested JSON with a query string
https://github.com/ayan-b/json_traverse
hacktoberfest
Last synced: 1 day ago
JSON representation
:palm_tree: Traverse a deeply nested JSON with a query string
- Host: GitHub
- URL: https://github.com/ayan-b/json_traverse
- Owner: ayan-b
- License: bsd-3-clause
- Created: 2020-02-22T13:14:46.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-10-31T17:55:39.000Z (about 2 years ago)
- Last Synced: 2023-08-20T22:28:57.858Z (over 1 year ago)
- Topics: hacktoberfest
- Language: Dart
- Homepage: https://pub.dev/packages/json_traverse
- Size: 631 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
JSON Traverser
Traverse a deeply nested JSON with a query string
Photo by Simone Dalmeri on Unsplash
[![Pub Package](https://img.shields.io/pub/v/json_traverse.svg)](https://pub.dev/packages/json_traverse)
[![Build Status](https://travis-ci.com/ayan-b/json_traverse.svg?branch=master)](https://travis-ci.com/ayan-b/json_traverse)```dart
import 'package:json_traverse/json_traverse.dart';void main() {
var jsonString = '''
{
"name": "John Smith",
"email": "[email protected]",
"contact": [
"123",
"456"
]
}
''';
var traverser = JSONTraverse(jsonString);
// for a single string
print(traverser.query('name')); // Prints `John Smith`
// for an array, point the index
print(traverser.query('contact.1')); // Prints `456`
}```
## Usage
First instantiate a `JSONTraverse` object: `JSONTraverse traverser = JSONTraverse(jsonString)`.
Now, use the `query` method to traverse through the JSON: `traverser.query('name')`.
If you want to traverse through an array, you have to mention the index, _e.g._,
`traverser.query('contact.1')` for index `1` of the contact array. If the index
is not a valid number, the code will throw a `FormatException`.## License
[BSD-3-Clause](./LICENSE)