Я посмотрел на следующие вопросы, потому что у меня были проблемы с интерполяцией строки JSON, но все еще были проблемы.
Вот код: (простите за горизонтальную прокрутку)
JSON_DATA=\''{"notification": {"title": "'"$TITLE"'", "body": "'"$BODY"'", "sound": "'"${SOUND}"'"}, "to": "'"$DEVICE_ID"'"}'\'
Что возвращает мне хорошо структурированную JSON (в строке).
'{"notification": {"title": "random test", "body": "here is big body", "sound": "default"}, "to": "ejKgihBpSt4:APA91bGBl"}'
Затем, когда я запускаю свой CURL:
curl -H "Content-type: application/json" -H "Authorization:key=$FIREBASE_SERVER_KEY" -X POST -d "$JSON_DATA" https://fcm.googleapis.com/fcm/send
, я получаю следующую ошибку: JSON_PARSING_ERROR: Unexpected character (') at position 0.
Если я помещаю $ {JSON_DATA} вне двойные кавычки, то я получаю следующую ошибку:
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: "random
curl: (6) Could not resolve host: test",
curl: (6) Could not resolve host: "body"
curl: (6) Could not resolve host: "here
curl: (6) Could not resolve host: is
curl: (6) Could not resolve host: big
curl: (6) Could not resolve host: body",
curl: (6) Could not resolve host: "sound"
curl: (3) [globbing] unmatched close brace/bracket in column 10
curl: (6) Could not resolve host: "to"
curl: (3) [globbing] unmatched close brace/bracket in column 24
JSON_PARSING_ERROR: Unexpected character (') at position 0.