psql's \set command unable to save json file's content in a variable
There here-doc feature in bash treats backticks as command invocations, so it executes the cat /tmp/jsonfile.json, which wrongfully injects the json contents into the psql commands:


  If word is unquoted, all lines of the here-document are subjected to
  parameter expansion, command substitution, and arithmetic expansion,
  the character sequence \newline is ignored, and ‘\’ must be used to
  quote the characters ‘\’, ‘$’, and ‘`’.


You may quote the EOF word to remove all expansions, as in :

psql [...] &lt;&lt; 'EOF'
... psql script...
\set var `cat /tmp/jsonfile.json`
...
EOF


That's the safest method when you don't need to inject anything from bash into the here-doc script.

Or, if any kind expansion in the here-doc string is needed, the above-mentioned characters must be quoted with backslash, as in:

myfile="/tmp/jsonfile.json"

psql [...] &lt;&lt; EOF
... psql script...
\\set var \`cat $myfile\`
...
EOF