How to convert a JSON object to key=value format in jq?

You could try:

jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' test.json

Here’s a demo:

$ cat test.json
{
    "var": 1,
    "foo": "bar",
    "x": "test"
}
$ jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' test.json
foo=bar
var=1
x=test

Leave a Comment