Skip to content

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

@texastoland

Description

@texastoland

Continued from discoveryjs/JsonDiscovery#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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions