Giter VIP home page Giter VIP logo

json_resolve's Introduction

json resolve

❤️ Support my apps ❤️

❤️❤️😇😍🤘❤️❤️

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, [email protected]

License

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

json_resolve's People

Contributors

onmyway133 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

json_resolve's Issues

Writing to a json

Hi,

Is there a way to write using keys path?
Do you pretend to implement?
I haven't found any packages that do writing using paths =[

Any sugestions?

Null Safety

Are you planning to migrate the repo to null safety?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.