JSON object cannot be decoded - tastypie - curl

I followed the tastypie textbook verbatim until I reached the post office: http://django-tastypie.readthedocs.org/en/latest/interacting.html#creating-a-new-resource-post

When I run this command, I get the following error: No JSON object could be decoded

I checked and I am sure that I am following the documentation verbatim.

thanks for the help

+4
source share
1 answer

It turned out that this is a window with cURL.

  • JSON data must be specified with double quotes ("") instead of single quotes.
  • All double quotes in the json package must be escaped with a backslash (\)

For example: So this is:

curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"body": "This will prbbly be my lst post.", "pub_date": "2011-05-22T00:46:38", "slug": "another-post", "title": "Another Post", "user": "/api/v1/user/1/"}' http://localhost:8000/api/v1/entry/

Must be:

curl --dump-header - -H "Content-Type: application/json" -X POST --data "{\"body\": \"This will prbbly be my lst post.\", \"pub_date\": \"2011-05-22T00:46:38\", \"slug\": \"another-post\", \"title\": \"Another Post\", \"user\": \"/api/v1/user/1/\"}" http://localhost:8000/api/v1/entry/

+14
source

All Articles