JSON in REST APIs β Interview Questions
β‘ Short Answer
In REST, JSON is the standard body format for both requests and responses. Clients send data as a JSON body with Content-Type: application/json (and Accept: application/json to ask for JSON back); the server parses it, does the work, and returns a JSON body plus the right status code. It's the common language between client and server.
βCoffee Chat Question
Concept Made Simple
βHow is JSON used in REST APIs?β
π§ Mind Map Answer
Remember It Faster
β¨οΈHands-on Keyboard
Learn by Doing
POST /api/users HTTP/1.1
Content-Type: application/json
Accept: application/json
{ "name": "Guru", "email": "guru@example.com" }
HTTP/1.1 201 Created
Content-Type: application/json
{ "id": 101, "name": "Guru" }π₯What If?
Think Beyond the Expected
What happens if you POST JSON without a Content-Type: application/json header?
The server may not know to parse the body as JSON β many frameworks only run the JSON body parser when Content-Type is application/json, so req.body ends up empty or a raw string. Always set the header; a mismatched or missing Content-Type is a very common 'why is my body undefined?' bug.
πReal World
This is the backbone of virtually every web/mobile app: the client GETs JSON to render, POSTs JSON forms, and the server returns JSON. The Content-Type/Accept headers are what make the exchange unambiguous.
π―Interviewer's Expectation
Keywords they're listening for:
β οΈCommon Mistakes
- βOmitting Content-Type: application/json
- βIgnoring the Accept header
- βReturning 200 for an error with an error body
β Best Practices
- βAlways set Content-Type and Accept
- βReturn correct status codes with JSON bodies
- βKeep request/response shapes documented
πFollow-up Questions
- 1What's the difference between request and response JSON?
- 2Which status codes pair with JSON error bodies?
- 3How does content negotiation work?
π§©Related Technologies
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly β AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: REST APIs (JSON) Interview question: "How is JSON used in REST APIs?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
β Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission β at no extra cost to you. It helps keep Full Stack Interview Guru free.