Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No JSON object could be decoded - tastypie - curl

I was following the tastypie tutorial word for word until i reached the post part: http://django-tastypie.readthedocs.org/en/latest/interacting.html#creating-a-new-resource-post

When i run this command i keep getting the following error: No JSON object could be decoded

I checked and I am certain that I am following the documentation word for word.

Thanks for your help

like image 453
nknj Avatar asked Jul 09 '12 20:07

nknj


1 Answers

Turned out to be a windows thing with cURL.

  1. The JSON data should be quoted with double quotes ("") instead of single quotes.
  2. All the double quotes in the json packet must be escaped with a backslash (\)

Eg: So, this:

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/

Should 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/

like image 143
nknj Avatar answered Nov 19 '22 02:11

nknj