Am trying insert a document into my cloudant as below.

@echo OFF
SPEECH_TEXT="Call me Ishmael. Some years ago-never mind how long precisely-"
curl -X POST -k 'https://<user id>.cloudant.com/testdb' -P 443 -H 'Content-Type:application/json' -d '{"transcript":"'"$SPEECH_TEXT"'"}' | jq-win64.exe

Getting below error:

  "error": "bad_request",
  "reason": "invalid UTF-8 JSON"

If I replace the variable with plain text in the command, it works fine. Any help much appreciated.


I normally go the printf route for clean code:


[user@localhost ~]$ SPEECH_TEXT="something"
[user@localhost ~]$ body=`printf '{"transcript":"%s"}' $SPEECH_TEXT`
[user@localhost ~]$ echo $body
[user@localhost ~]$ 

In your case:

curl -X POST -k 'https://cloudant.com/testdb' -P 443 -H 'Content-Type:application/json' -d `printf '{"transcript":"%s"}' $SPEECH_TEXT`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.