h2non / jsonpath-ng

Finally, a JSONPath implementation for Python that aims to be standard compliant. That's all. Enjoy!
Apache License 2.0
572 stars 85 forks source link

Return null for missing property/leaf #82

Open brno32 opened 3 years ago

brno32 commented 3 years ago

given

[
    {"name": "Test Account"},
    {}
]

$.[*].name returns

[
   "Test Account"
]

but I'd like for it to return

[
   "Test Account",
    None
]

https://jsonpath.herokuapp.com/ let's you decide whether or not to return null in this case. Does such a flag exist here?

EDIT:

I found the find_or_create method, which would put an empty dict in the place of None. Would it be possible to customize the created value?

sadilet commented 2 years ago

any updates on this? @brno32 could you tell me how did you solve it eventually? I'm facing this issue now, thinking to override find_or_create method

brno32 commented 2 years ago

I gave up on this library unfortunately. Overriding find_or_create might be a good approach

Johnserf-Seed commented 9 months ago

Yes, I had a similar problem. I need a field that doesn't necessarily exist, and when I use $.list[*].key[0] to match it only returns the found field instead of replacing its index with None !

Is there a good solution?