Bird
0
0

You want to send JSON data {"name":"John"} to http://api.example.com/users using curl. Which command has an error?

medium📝 Debug Q14 of 15
Linux CLI - Networking Commands
You want to send JSON data {"name":"John"} to http://api.example.com/users using curl. Which command has an error?
Acurl -d '{name:John}' -X POST -H "Content-Type: application/json" http://api.example.com/users
Bcurl -X POST -H "Content-Type: application/json" -d '{"name":"John"}' http://api.example.com/users
Ccurl -d '{"name":"John"}' http://api.example.com/users -H "Content-Type: application/json" -X POST
Dcurl -X POST -d '{"name":"John"}' -H "Content-Type: application/json" http://api.example.com/users
Step-by-Step Solution
Solution:
  1. Step 1: Check JSON data format

    curl -d '{name:John}' -X POST -H "Content-Type: application/json" http://api.example.com/users uses '{name:John}' which misses double quotes around keys and values, making it invalid JSON. Options A, C, D use correct JSON '{"name":"John"}'.
  2. Step 2: Confirm curl flags order

    Order of flags does not matter in curl, so A, C, D are valid. Only data format in B is wrong.
  3. Final Answer:

    curl -d '{name:John}' -X POST -H "Content-Type: application/json" http://api.example.com/users -> Option A
  4. Quick Check:

    JSON must have quotes [OK]
Quick Trick: JSON keys and values need quotes [OK]
Common Mistakes:
  • Omitting quotes in JSON data
  • Thinking flag order matters in curl
  • Using wrong content-type header

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes