jora icon indicating copy to clipboard operation
jora copied to clipboard

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

Open texastoland opened this issue 4 years ago • 2 comments

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 avatar May 07 '21 14:05 texastoland

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 avatar Apr 04 '22 05:04 texastoland

Annual ping for shorthand syntax 🙏🏼

texastoland avatar Jan 08 '24 23:01 texastoland