gjson icon indicating copy to clipboard operation
gjson copied to clipboard

"any depth" wildchar

Open kikyous opened this issue 3 weeks ago • 5 comments

* match only one level key: *.*.*.*.deepKey

It's nice if there is a "any depth" wildchar **, for example

**.deepKey

**deepKey

kikyous avatar Nov 29 '25 06:11 kikyous

@kikyous that should be doable with the @dig modifier, see the Modifiers documentation.

For example with a json of:

{ "something": {
    "anything": {
      "abcdefg": {
          "finally": {
            "important": {
                "secret": "password"
            }
        }
      }
    }
  }
}

and a query @dig:secret you get:

["password"]

volans- avatar Nov 29 '25 14:11 volans-

@volans- thanks for comment. @dig modifier is an approach, but wildchar is more flexible and intuitive, and modifier can not used in sjson

kikyous avatar Nov 29 '25 15:11 kikyous

I make a i18n editor: https://github.com/kikyous/i18nedt, basically it's a wrapper on gjson and sjson. It could be convenient to use "any depth" wildchar to get and update a i18n key, like:

i18nedt src/locales/*.json -k **.submitTip

or

i18nedt src/locales/*.json -k **.homework.submitTip

kikyous avatar Nov 29 '25 15:11 kikyous

I see. As far as I know the Path functionality to get the effective path don't work with modifiers (otherwise it could allow to get the Path for it and then use the exact path in the rest of the calls) but I'll leave the authoritative answer to @tidwall.

volans- avatar Nov 29 '25 22:11 volans-

In order to use @dig or a new **-type path for the purpose of modifying the values (such as with sjson), the positions of the results would need to be mapped. The Path functionality, and Index field in particular work by mapping the result to underlying json document.

Unfortunately, modifiers like@dig create new json documents that are not a subset of the original.

To make it work in the way @kikyous is describing, the indexes of the results of @dig and ** would need to be saved somehow.

tidwall avatar Nov 30 '25 11:11 tidwall