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

Cannot filter array by non-existent field. #151

Open
Klwilson2272 opened this issue Nov 22, 2023 · 1 comment
Open

Cannot filter array by non-existent field. #151

Klwilson2272 opened this issue Nov 22, 2023 · 1 comment

Comments

@Klwilson2272
Copy link

Klwilson2272 commented Nov 22, 2023

Example data set returned by querying all records.

qv: $.StatementsOfIncome.RevenueFromContractWithCustomerExcludingAssessedTax[*] version: 1.6.0

{'decimals': '-6', 'unitRef': 'usd', 'period': {'startDate': '2022-09-25', 'endDate': '2023-09-30'}, 'segment': {'dimension': 'srt:ProductOrServiceAxis', 'value': 'us-gaap:ProductMember'}, 'value': '298085000000'}
{'decimals': '-6', 'unitRef': 'usd', 'period': {'startDate': '2022-09-25', 'endDate': '2023-09-30'}, 'value': '383285000000'}

I am interested in selecting the rows without a 'segment'. However, when I specify the filter:

match = xpathQuery(f"$.{section}.{property}[?!(@.segment)]")
[ print(m.value) for m in match]

I get a error on unexpected character: !

And if I alter this to attempt:

match = xpathQuery(f"$.{section}.{property}[?(@.segment==null)]")
[ print(m.value) for m in match]

The results are empty.

Proving the syntax is correct. I change the query to:

match = xpathQuery(f"$.{section}.{property}[?(@.segment!=null)]")
[ print(m.value) for m in match]

This returns just the row with a segment field.

{'decimals': '-6', 'unitRef': 'usd', 'period': {'startDate': '2022-09-25', 'endDate': '2023-09-30'}, 'segment': {'dimension': 'srt:ProductOrServiceAxis', 'value': 'us-gaap:ProductMember'}, 'value': '298085000000'}

How can I tell the query to only respond with rows without a segment?
expect to be able to query: {'decimals': '-6', 'unitRef': 'usd', 'period': {'startDate': '2022-09-25', 'End Date': '2023-09-30'}, 'value': '383285000000'}

This seems so simple, but it seems the feature is missing.

In python I can wrap the query, but this circumvents the upper layers of the application specifying the selection criteria.

@Klwilson2272
Copy link
Author

Java JsonPath library handles this by setting a optional configuration to return NULL for the leaf.
https://stackoverflow.com/questions/48109347/json-path-field-null-checking-expression

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

No branches or pull requests

1 participant