EasyπŸ‘€ 0-2 yearsπŸ‘€ 3-5 years 1 min read

JSON in REST APIs β€” Interview Questions

Asked inInfosysTCSAccentureAmazon
#json#rest api#content-type#application/json#http
Report issue

⚑ 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

Request body→JSON for POST/PUT/PATCH
Response body→JSON result or error
Content-Type→application/json (what you send)
Accept→application/json (what you want back)

⌨️Hands-on Keyboard

Learn by Doing

http
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:

βœ“ JSON request & response bodiesβœ“ Content-Type: application/jsonβœ“ Accept headerβœ“ server parses & returns JSONβœ“ status code + body

⚠️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

RESTHTTP headerscontent negotiationOpenAPI

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?

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.

Related Questions