Coder Social home page Coder Social logo

linw1995 / jsonpath Goto Github PK

View Code? Open in Web Editor NEW
38.0 1.0 3.0 739 KB

A query expression for extracting data from JSON.

Home Page: https://jsonpath.rtfd.io/en/latest/

License: MIT License

Makefile 2.29% Python 97.71%
jsonpath data-extractor data-extraction cli

jsonpath's People

Stargazers

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

Watchers

 avatar

jsonpath's Issues

Source distribution built by poetry is not working with pip.

Probably it's intreehooks causing this problem. Sdist (Source distribution) of poetry and pdm built by using the intreehooks is not working with pip too. The elder version 0.12.17 of poetry, without using intreehooks, is working well with pip.

build.py file contaminates the site-packages directory

The build.py file contaminates the site-packages directory after installing jsonpath-extractor.

build.py is for doing code-gen, generating the standalone parser via lark-parser.
And it is to be run for building dist-wheel or for installing the source code.

workaround solutions

  1. Make build.py as a module of the jsonpath package.
  2. Make build.py as a submodule of the jsonpath namespace package.

Is it possible to get None when the value is not present in a specific array item?

Hi and thank you for putting together this really helpful package!

I have a use case where I would like to keep matched objects synchronized.

For instance, using the data from the documentation:

from jsonpath import parse
data = {
    "goods": [
        {"price": 100, "category": "Comic book"},
        {"price": 200, "category": "magazine"},
        {"price": 200, "no category": ""}
    ],
    "targetCategory": "book"
}

I would like to extract price and category keys into lists, but lists must have same lengths.

The following expression:

parse("$.goods[*].category").find(data)

outputs all matching items (which is already super cool :)) :

['Comic book', 'magazine',]

Is there a way to add 'None' for array items that do not contain the category key? I.e. having the following output:

['Comic book', 'magazine', None]

(Or any other way to achieve the desired result?)

Empty result

Hi!,

I have the following JSON:

[{
    "author": [
        {
            "fullname": "some fullname",
            "rank": 3
        },
        {
            "fullname": "other fullname",
            "pid": {
                "id": {
                    "scheme": "orcid",
                    "value": "0000-0000-0000-0000"
                },
                "provenance": {
                    "provenance": "Harvested",
                    "trust": "0.91"
                }
            },
            "rank": 4
        }
    ]
}]

and the following jsonpath expression:
$.*.author[*]

But I get empty results, which is not the same behaviour online tool.

Thank you in advance! :)

WIP Feature request for object conversion

Implements a simple and easy for usage syntax for object conversion.

Functions

Common Conversion

assert parse("${a:b, b:a}") \
    .find({"a": 1, "b": 2}) == [{"b": 1, "a": 2}], "swaps values between a and b" 
assert parse("${username:author_name, age:author_age}") \
    .find({
        "author_name": "Jade",
        "author_age": 18,
        "boo": "boo"
    }) == [{"username": "Jade", "age": 18}], "Rearranges the key-value pairs"

Conversion Can Be Applied To Array

assert parse("$[{a:b}]").find([{"b": 1}, {"c": 1}]) == [{"a": 1}, {"a": None}]
assert parse("$[{a:b}][a != null]").find([{"b": 1}, {"c": 1}]) == [{"a": 1}]

Nested Conversion

assert parse("${author: {name: author_name}}") \
    .find({"author_name": "Jade"}) == [{"author": {"name": "Jade"}}]

Or the key of the key-value pair may be chained path which components are name only, e.g. boo.bar

assert parse("${author.name: author_name}") \
    .find({"author_name": "Jade"}) == [{"author": {"name": "Jade"}}]

The Value Of The Key-Value Pair May Be An Expression

assert parse("${name: author.name}") \
    .find({"author": {"name": "Jade"}}) == [{"name": "Jade"}]

WIP Update key-value pairs

JSONpath expression not retrieving results

Hi!

I have the following data:

[
   {
      "title":[
         "some title"
      ],
      "creator":[
         {
            "fullname":"WWWW ZZZZ",
            "name":"WWWW",
            "surname":"ZZZZ"
         },
         {
            "fullname":"XXXX YYYY",
            "name":"XXXX",
            "surname":"YYYY"
         }
      ],
      "id":2157
   }
]

Is the expression $[*].(title,id) supported (with other syntax)?

Thanks in advance :)
Julián

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.