Akshay Gopani
Akshay Gopani

Reputation: 491

JQ raw text to double quoted key value pair

I have this data. {"bucket":"sdsd","key":"hghghg","region":"us-east-1"} I want to convert it into following format. using shell commands.

Upvotes: 0

Views: 125

Answers (1)

pmf
pmf

Reputation: 36058

Use to_entries to access keys and values. To escape with quotes, it may not be sufficient to just put quotes around the names. Depending on your use case, converting to JSON strings using @json might be an option:

jq -r 'to_entries[] | @json "\(.key) = \(.value)"'
"bucket" = "sdsd"
"key" = "hghghg"
"region" = "us-east-1"

Demo

Upvotes: 3

Related Questions