Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stellasia opened this issue Jan 19, 2022 · 0 comments · May be fixed by #41
Open

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

stellasia opened this issue Jan 19, 2022 · 0 comments · May be fixed by #41

Comments

@stellasia
Copy link

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?)

@linw1995 linw1995 linked a pull request Jan 25, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant