A simple transformation of your working code (also moving to lower-case variable names, as per convention for variable names not reserved for shell or system use):
payload=$(jq -n --argfile attach <(printf '%s
' "$final_json") '{
"attachments":$attach
}')
I'm sticking with --argfile
here since it parses the file's contents as JSON; using --arg
wouldn't have that effect.
The <(...)
syntax is process substitution, which is replaced with a filename for a named pipe or temporary file connected to the content in question.
However, you can also use --arg
, and apply the fromjson
filter to parse as JSON:
payload=$(jq -n --arg attach "$final_json" '{
"attachments":$attach|fromjson
}')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…