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

Querying nested optional array #331

Closed
mgdemers opened this issue Sep 14, 2023 · 2 comments
Closed

Querying nested optional array #331

mgdemers opened this issue Sep 14, 2023 · 2 comments

Comments

@mgdemers
Copy link

mgdemers commented Sep 14, 2023

I am looking to retrieve values from a nested array that may not always be present, and preserve the array ordering in the result.

Example JSON:

{
    "outer": {
         "middle": [
             {
                 "otherKey": "otherVal"
             },
              {
                 "otherKey": "otherVal",
                 "inner": [{"key": "value"}, {"key": "value2"}]
             },
             {
                 "inner": [{"key": "value3"}]
             },
	    {
		    "inner": null
	    }
         ]
    }
}

Ideally, I want to get something like this output:

[nil, ["value","value2"],["value3"], nil]

Based on comments in #295, I've tried a few variations of queries with defaults defined, but the null or omitted keys are still dropped from the results:

outer.[middle, !null].0.#.[inner, !null].0.#.[key, !null].0 -> [["value","value2"],["value3"]]

The closest I've come is here, where the general structure is still defined, but technically wrapped in one extra layer of brackets:

outer.[middle, !null].0.#.[inner, !null].[0.#.key, !null]  ->  [[],[["value","value2"]],[["value3"]],[]]

Any ideas for how I can preserve the empty & missing arrays is greatly appreciated!

@volans-
Copy link

volans- commented Sep 15, 2023

@mgdemers I think that the problem in your query are the spaces and in your last example you're missing a .0 at the end, with:

outer.[middle,!null].0.#.[inner,!null].[0.#.key,!null].0

I get

[null,["value","value2"],["value3"],null]

That I believe is what you're looking for.

@mgdemers
Copy link
Author

Thanks @volans- , removing the spaces was what I needed.

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

2 participants