EasyExperience level: 0-2 years · 3-5 years1 min read

JSON in REST APIs — Interview Questions

Reviewed by Gurusankar M.

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.

On this page

Concept Made Simple

Coffee Chat Question

“How is JSON used in REST APIs?”

Remember It Faster

Mind Map Answer

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)

Learn by Doing

Hands-on Keyboard

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" }

Think Beyond the Expected

What If?

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

  1. What's the difference between request and response JSON?
  2. Which status codes pair with JSON error bodies?
  3. How does content negotiation work?

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.
Open inChatGPTGeminiClaude

Was this answer helpful?

Affiliate links

Equipment for a comfortable, productive setup.

As an Amazon Associate I earn from qualifying purchases.