json_resolve 1.0.0

json resolve #

Description #

json_resolve is a Dart library that helps accessing property in deep json object easily using keypath

Given the following deeply nested json

{
    "movie": "isFun",
    "earth": 199999,
    "dc": [
      {
        "name": "Superman"
      },
      {
        "name": "Flash"
      },
      {
        "name": "Wonder Woman"
      }
    ],
    "marvel": [
      {
        "name": "Thor",
        "weapon": "Mjolnir",
        "appear": [
          {
            "year": 2011,
            "title": "Thor"
          },
          {
            "year": 2013,
            "title": "The Dark World"
          },
          {
            "year": 2017,
            "title": "Ragnarok"
          }
        ]
      }
    ]
}

We can access using keypath. The library ensures safe type checking and casting, and use provided default value as last resort

final String byProperty = resolve(json: json, path: "movie", defaultValue: "error");
expect(byProperty, "isFun");

final int byInt = resolve(json: json, path: "earth", defaultValue: 0);
expect(byInt, 199999);

final String byIndex = resolve(json: json, path: "dc.2.name", defaultValue: "error");
expect(byIndex, "Wonder Woman");

final String byIndexThenProperty = resolve(json: json, path: "marvel.0.appear.1.title", defaultValue: "error");
expect(byIndexThenProperty, "The Dark World");

Installation #

First of all add the following dependencies to your pubspec.yaml:

dependencies:
  json_resolve: ^1.0.0

Author #

Khoa Pham, onmyway133@gmail.com

License #

json_resolve is available under the MIT license. See the LICENSE file for more info.

Use this package as a library

1. Depend on it

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


dependencies:
  json_resolve: ^1.0.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_resolve/json_resolve.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
73
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
50
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

We analyzed this package on Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:json_resolve/json_resolve.dart.

Health suggestions

Format lib/json_resolve.dart.

Run dartfmt to format lib/json_resolve.dart.

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and json_resolve.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <3.0.0
Dev dependencies
test >=0.12.42 <2.0.0