JSON to plain text using jq

Viewed 1409

Let's say i got the following json response:

{
  "author": "tomek",
  "title": "helloworld",
  "test": "sampletextonetwothree"
}

Is it possible to display something like this: (using jq)

author=tomek
title=helloworld
test=sampletextonetwothree
3 Answers
jq 'to_entries[] | "\(.key)=\(.value)"'

should do it

Another way to join the values is to use string concatenation:

jq -r 'to_entries[] | .key + "=" + .value'

There is probably a better way, but this works:

cat response.json | jq -r 'to_entries| map([.key, .value]) | map([join("=")]) | flatten | .[]'

or

cat response.json | jq -r 'to_entries | map([.key, .value]) | .[] | join("=")'
Related