0

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":"raj@example.com","password":"samplepassword" }"

curl --location "http://127.0.0.1:5000/user/signup" --header "Content-Type: application/json" --data-raw '{ "name": "Raj Kumar", "email": "raj@example.com", "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:raj@example.com,password:samplepassword }

curl: (3) URL using bad/illegal format or missing URL

Postman:
enter image description here

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:

ni6hant
  • 23
  • 6
  • I later found out gitbash works as intended. But I still want to know the answer to this. – ni6hant May 15 '23 at 12:55
  • Single quotes might not work everywhere, https://stackoverflow.com/a/24499743/1427878 - but using double quotes as delimiters, and escaping any double quote inside the value with a backslash, should always work. – CBroe May 15 '23 at 13:12
  • Thanks CBroe. I completely forgot about escaping characters and used to remove / from curl code – ni6hant May 19 '23 at 06:45

1 Answers1

0

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":"raj@example.com","password":"samplepassword" }'

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37