mocart
mocart

Reputation: 615

print all json objects as string using jq utility

I have a JSON value:

{
  "ssh_key": {
    "id": 123
  }
}

How i can print id object by jq utility as string? Object value must be (with double quotas):

{
  "id": "123"
}

I use jq '.ssh_key | {id} command for print without double quotes now.

Thanks.

Upvotes: 1

Views: 1173

Answers (1)

pmf
pmf

Reputation: 36131

Use the tostring (or the @text) builtin to convert into a string:

jq '.ssh_key | .id |= tostring'
{
  "id": "123"
}

Demo

Upvotes: 4

Related Questions