Search code examples
jsoncurlibm-watsontone-analyzer

IBM Watson Tone Analyzer Invalid JSON Error


I must be missing something very simple here. I am following the Example Tutorial Instructions. I already created a free account and I have my API key and the URL. I copied the JSON file as instructed. Here is the command I issued:

curl -X POST -u "apikey:MY-API-KEY" \
--header "Content-Type: application/json" \
--data-binary PATH-TO-FILE \
"MY-URL"
  • Where MY-API-KEY equals my personal key specified on my Manage page.
  • Where PATH-TO-FILE equals the path to my local copy of tone.json
  • Where MY-URL equals the url specified on my Manage page.

Here is the error I am getting:

{"code":400,"sub_code":"C00012","error":"Invalid JSON input at line 1, column 2"}

I copied the JSON exactly from the directions:

{
  "text": "Team, I know that times are tough! Product sales have been disappointing for the past three quarters. We have a competitive product, but we need to do a better job of selling it!"
}

I also attempted the following JSON and it received the same error:

{"text":"Hello world"}

What obvious thing am I missing here?


Solution

  • I knew it was going to be something silly.

    The directions have this as an example:

    curl -X POST -u "apikey:{apikey}" \
    --header "Content-Type: application/json" \
    --data-binary @{path_to_file}tone.json \
    "{url}/v3/tone?version=2017-09-21"
    

    For the path to the file, I had to keep the @ symbol in front. so let's assume the full path to the file is /home/joe/Desktop/tone.json, that line has to be:

    --data-binary @/home/joe/Desktop/tone.json \