json_traverse 0.1.0 copy "json_traverse: ^0.1.0" to clipboard
json_traverse: ^0.1.0 copied to clipboard

Parse deeply nested JSON using simple query strings with dot separator.

JSON Traverser

Traverse a deeply nested JSON with a query string
Photo by Simone Dalmeri on Unsplash




Pub Package Build Status

import 'package:json_traverse/json_traverse.dart';

void main() {
  var jsonString = '''
  {
    "name": "John Smith",
    "email": "john@example.org",
    "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

5
likes
40
pub points
0%
popularity

Publisher

unverified uploader

Parse deeply nested JSON using simple query strings with dot separator.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (LICENSE)

More

Packages that depend on json_traverse