Juicy
Juicy

Reputation: 12500

Get all values and nested values that match a key name

I have some data that looks like:

{
  "hello": {
     "foo": "x",
     "y": "z"
  },
  "foo": "a",
  "bar": {
    {
      "foo": "b"
    }
  }
}

How can I get all values with key foo, wherever they are?

Upvotes: 1

Views: 50

Answers (1)

AnonymousSB
AnonymousSB

Reputation: 3604

You can search using recursive decent

Solution

jq '..|.foo?'

Demo

https://jqplay.org/s/Xp64LfJFBc

Documentation

https://stedolan.github.io/jq/manual/#RecursiveDescent:..

Upvotes: 2

Related Questions