Home > front end >  print json object like {key:value} by jq utiliity
print json object like {key:value} by jq utiliity

Time:11-26

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"

CodePudding user response:

This is the working solution:

jq '.ssh_key | {id}'

which outputs:

{
  "id": 123
}
  • Related