discoveryjs / browser-extension-json-discovery

A browser extension (Chrome, Edge, Firefox) that changes the way you're viewing JSON
305 stars 11 forks source link

Recursive descent operator not working #68

Closed texastoland closed 3 years ago

texastoland commented 3 years ago

I can't get ..ident (for non-child keys) to work from the report screen.

exdis commented 3 years ago

Could you describe the problem in more detail?

texastoland commented 3 years ago

Example JSON Report

Expected:

Many results.

Actual:

1 result.

lahmatiy commented 3 years ago

@texastoland This question is jora (query language) related. Operator .. works this way:

  1. Apply subquery (on the right side) to a value (on the left)
  2. For each item of result in step 1 (it may be multiple because of array) never seen before apply step 1
  3. If all returned by subquery values already seen – return a result of unique values

In your case, at first iteration version applies to the top level object and returns a string. Ar second iteration it applies to the string and returns undefined -> return a result.

In case you want to get dependency tree in package-lock.json as a list, you should use something like that:

..(dependencies.values())

But you will loose packages names. Fix that:

..(dependencies.entries().({ name: key, ...value }))

Hope it helps. Closing since it's not a bug.

texastoland commented 3 years ago

Wow thanks for the thorough explanation! I had assumed it worked like .. in jq or in E4X to find a version at any depth. Is there something equivalent? Would it be worth tracking a request in the other repo?

lahmatiy commented 3 years ago

...to find a version at any depth. Is there something equivalent?

It's possible with jora, but there is no special operator for this. Something like this:

..values().[version].version

What's your use case? I did not feel the need for this functionality in my tasks. You could open an issue with a discussion in jora issues.