Search code examples
jqjson-path-expression

How can I use a relative Path or a Wildcard in JQ


Is it possible to use a relative path or name in JQ like the XPath // ?

Or is it possible to use an wildcard in JQ like .level1.*.level3.element ?


Solution

  • That's what the .. filter was meant to represent. The use would look like this:

    .level1 | .. | .level3? .element
    

    Note: you must use the ? otherwise you'll get errors as it recurses down objects that do not have the corresponding property.