cURL post JSON data on Windows

On Windows, the key to send JSON data is double-quotes like this


-d "{\"name\":\"Spring Forever\"}"

cURL to POST a JSON data


 curl -X POST localhost:8080/books
	-H "Content-type:application/json" 
	-d "{\"name\":\"Spring Forever\",\"author\":\"pivotal\"}"

References

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

7 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
RANA
5 years ago

Great. This solved my problem.

Brent
3 years ago

I appreciate your posts. Thank you!

Paulo H A
3 years ago

Muito obrigado!

Ahren Bader-Jarvis
5 years ago

Thank you! I couldn’t figure out why the same command worked on Linux and not on Windows. This was the simple solution I needed. 🙂

Maciek S
3 months ago

Escaping like this works on Windows only from command line. when you script then escape character is: ^ (it is not \). BTW if you use long access token or large data payload then you will exceed command line Windows limit of 1024 characters giving you odd and unrelated errors that Microsoft engineering could not figure out better message: “error: content truncated”.

sigmud
7 months ago

Thanks a lot – sometimes working in CMD feels like fighting the windmills

Vinícius
2 years ago

Thank you!
Obrigado!
Gracias!