Issue
When I give the following curl command (and various other formats below), I keep encountering error, however it posts just fine with Postman:
curl --location "http://localhost:5000/user/signup" --header "Content-Type:application/json" --data-raw "{ "name":"Raj Kumar","email":"[email protected]","password":"samplepassword" }"
curl --location "http://127.0.0.1:5000/user/signup" --header "Content-Type: application/json" --data-raw '{ "name": "Raj Kumar", "email": "[email protected]", "password": "samplepassword" }'
Errors I get:
Failed to decode JSON object: Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
curl: (3) unmatched close brace/bracket in URL position 53:
Kumar,email:[email protected],password:samplepassword }
curl: (3) URL using bad/illegal format or missing URL
I have tried formatting the code multiple times but it doesn't seem to work. I also tried swapping the double quotes with single ones too.
I was expecting the same output as Postman below:
Solution
The problem is the double quotes in the Json. Using single quotes around the Json, and double quotes within will work:
curl --location "http://localhost:5000/user/signup" --header "Content-Type: application/json" --data-raw '{ "name":"Raj Kumar","email":"[email protected]","password":"samplepassword" }'
Answered By - Christian Baumann Answer Checked By - David Goodson (WPSolving Volunteer)