Reputation: 1201
My input JSON is of the format:
{
"a": "apple",
"b": "banana",
"c": 5,
"d": ["this", "is", "an", "array"],
"e": false
}
What I want is:
a="apple"
b="banana"
c=5
d=["this", "is", "an", "array"]
e=false
Note that only strings in the input JSON have quotes in the output.
By using jq -r 'to_entries[] | "\(.key)=\"\(.value)\""'
I could generate an output like
a="apple"
b="banana"
c="5"
d="["this", "is", "an", "array"]"
e="false"
So my question is:
Upvotes: 0
Views: 219
Reputation: 2045
You can test whether .value is a string or not using type
(manual entry).
jq -r 'to_entries[]
| "\(.key) = \( .value
| if type == "string"
then "\"\(.)\""
else .
end
)"'
Upvotes: 2