I would like to read a file and put the whole content into a single string that is escaped to be used in a JSON object.
And I want to do it on the commandline/terminal (Linux).
WARNING: With this solution the content of the file can be too big to fit in an argument!
jq -n \
--arg content "$(cat theFile.txt)" \
'{ theContent : $content }' \
| \
jq '.theContent'
Jeff Mercado provided a more compact solution for the first part - so I adapted that in my code as follows:
jq -Rs \
'{ theContent: . }' \
theFile.txt \
| \
jq '.theContent'
Now Jeff Mercado provided a more compact solution for what I was looking for:
jq -Rs '.' theFile.txt