mocart
mocart

Reputation: 615

print json object like {key:value} by jq utiliity

i have json:

{
  "ssh_key": 
    {
      "id": 123,
      "public_key": "ssh-rsa 1233123333333333333dafseg345345345",
      "name": "MY.PUB.KEY",
      "fingerprint": "94:45:54:22:3f:55:ff:55"
    }
}

i can't print only 1 object {"id":123} with jq, i tryed like this:

jq '.ssh_key | to_entries[] | {"id": .key, "value": .value.id}'
jq: error (at <stdin>:1): Cannot index number with string "id"

Upvotes: 0

Views: 55

Answers (1)

Ron
Ron

Reputation: 6621

This is the working solution:

jq '.ssh_key | {id}'

which outputs:

{
  "id": 123
}

Upvotes: 1

Related Questions