I know that jq
can take serialized JSON strings to format/filter/modify the content. However, as far as I know the output is always human readable form of JSON. Is there a way in Bash or jq
itself, to stringify the output?
For example, given
echo '{"foo" : "bar"}' | jq -r .
I'm looking for an output that is "{\"foo\" : \"bar\"}"
CodePudding user response:
You want -R
, aka --raw-input
, to make jq treat your input as a string instead of as an object.
echo '{"foo" : "bar"}' | jq -R .