json_traverse 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 54

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

CHANGELOG #

0.1.0 #

  • First public release

0.0.2 #

  • Pedantic style checking
  • Detailed instructions in README
  • Add documentations

0.0.1 #

Initial release. Support for nested JSON and arrays.

example/example.dart

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`
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  json_traverse: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:json_traverse/json_traverse.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
9
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Mar 30, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
Dev dependencies
pedantic ^1.8.0
test >=0.12.0 <2.0.0