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

.. operator doesn't work as expected (based on prior art) #27

Open
texastoland opened this issue May 7, 2021 · 2 comments
Open

.. operator doesn't work as expected (based on prior art) #27

texastoland opened this issue May 7, 2021 · 2 comments

Comments

@texastoland
Copy link

texastoland commented May 7, 2021

Continued from discoveryjs/browser-extension-json-discovery#68.

Example

JSON

{
    "one": {
        "one" : 1,
        "two" : 2
    },
    "two": {
        "one" : 3,
        "two" : 4
    }
}

Filter As Tested

..one

Current Workaroud

($ + ..values()).one

Result

Expected:

Like $..one in JSONPath or ..|.one? in jq (playgrounds linked):

[
  {
    "one": 1,
    "two": 2
  }, // .one
  1, // .one.one
  3  // .two.one
]

query..subquery returns the query filtered by the subquery and recursively applies the filter to each child. (See use cases below.)

Actual:

[
    {
        "one": 1,
        "two": 2
    }, // .one
    1  // .one.one
]

query..subquery returns the query filtered by the subquery and recursively applies the filter to each result. (I'm curious about potential use cases.)

Use Cases

Example JSON

Save Typing

Example: ..isarray vs .dependencies.isarray

Quickly find an item (especially using the browser extension) without traversing its parent hierarchy.

Traverse Recursive Schemas

Example: ..isobject vs ..values().isobject

Find an item that may appear arbitrarily deep (dependencies have dependencies have dependencies and so on).

Align with Prior Art

The .. operator has a history (documentation linked):

  1. JSONPath
  2. jq
  3. E4X (former EcmaScript standard and spiritual predecessor of the above projects as well as JSX)
@texastoland
Copy link
Author

texastoland commented Apr 4, 2022

Is this open to change? I still have to reference this topic to explore JSON in JsonDicovery (which I love otherwise). It's just unintuitive to dig arbitrarily deep into a tree which is what I usually want to accomplish.

@texastoland
Copy link
Author

Annual ping for shorthand syntax 🙏🏼

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