Skip to main content
Postman Testing
CHAPTER 08 Beginner

Working with JSON Request Bodies

Updated: May 13, 2026
20 min read

# CHAPTER 8

Working with JSON Request Bodies

1. Introduction

When creating or updating data (using POST, PUT, or PATCH methods), you need a way to send the actual information—like a user's name, email, and age—to the server. This data is sent in the Request Body. In modern API development, the undisputed standard format for this data is JSON (JavaScript Object Notation). In this chapter, we will learn how to write valid JSON, configure Postman to send it correctly, and avoid the most common syntax errors that crash API requests.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Understand the basic syntax rules of JSON.
  • Use the Postman "Body" tab to construct raw JSON payloads.
  • Differentiate between JSON, form-data, and x-www-form-urlencoded.
  • Identify and fix common JSON syntax errors in Postman.

3. Beginner-Friendly Explanation

Imagine mailing a package to a friend. The URL is the address on the box. The Headers are the postage stamps and handling instructions ("Fragile!"). The Body is the actual contents inside the box.

If you just throw loose items into the box, your friend won't know how to organize them. You need to package them neatly. JSON is the standardized packaging material of the internet. It forces you to organize your data into clean "Key-Value" pairs, like a dictionary. "Name is John. Age is 30." When the server opens the box, it knows exactly how to read the contents.

4. Real-World Examples

  • Creating a User: A frontend registration form takes the user's input, converts it into a JSON body, and sends a POST request to the API to save it in the database.
  • Configuring Settings: A mobile app updates a user's notification preferences by sending a PATCH request with a JSON body containing {"pushNotifications": false}.

5. JSON Syntax Basics

Before we use Postman, you must know how to write valid JSON. It is very strict!
  • Data is in name/value pairs.
  • Pairs are separated by commas.
  • Curly braces {} hold objects.
  • Square brackets [] hold arrays (lists).
  • CRITICAL: All keys (names) *must* be wrapped in double quotes "".
  • CRITICAL: String values must be wrapped in double quotes "". Numbers and booleans (true/false) do not use quotes.

Valid JSON Example:

json
1234567
{
  "firstName": "John",
  "lastName": "Doe",
  "age": 28,
  "isActive": true,
  "hobbies": ["reading", "gaming"]
}

6. Step-by-Step Tutorial (Sending JSON in Postman)

Let's send a payload to our test API.
  1. 1. Open Postman, create a new request.
  1. 2. Set the Method to POST.
  1. 3. Set the URL to: https://jsonplaceholder.typicode.com/posts
  1. 4. Click the Body tab (below the URL bar).
  1. 5. Select the raw radio button.
  1. 6. Look to the far right of the Body formatting bar. You will see a blue dropdown that says Text. Click it and change it to JSON. *(This automatically adds the Content-Type: application/json header!)*
  1. 7. In the large text area, paste the following:
json
12345
{
  "title": "Learning Postman",
  "body": "JSON bodies are easy once you know the syntax.",
  "userId": 5
}
  1. 8. Click Send.
  1. 9. The server will respond with a 201 Created status and return your data with a newly generated id.

7. Other Body Formats in Postman

While JSON is standard for APIs, Postman supports other legacy/specialized formats:
  • form-data: Used specifically when you need to upload physical files (like an image or PDF) alongside text data. It mimics an HTML <form>.
  • x-www-form-urlencoded: The default way basic HTML forms send text data. It looks like URL query parameters (name=John&age=30), but it is hidden in the body.
  • GraphQL: Postman has a dedicated tab for GraphQL, which allows you to write GraphQL queries instead of raw JSON.

8. Handling JSON Errors in Postman

Postman is very helpful when you make a mistake. If you forget a comma, or use a single quote (') instead of a double quote ("), Postman will display a small red "x" next to the line number in the Body editor. If you hover over the red "x", it will tell you exactly what is wrong (e.g., "Expected a comma").

Always fix red "x" errors before clicking Send. If Postman flags it, the server will almost certainly reject it with a 400 Bad Request error.

9. Best Practices

  • Use the JSON formatter button: In the Body editor, if your JSON looks messy, right-click anywhere in the editor text and select "Format Document" (or use the shortcut Beautify). This aligns all your brackets perfectly.
  • Never put trailing commas: JSON strictly forbids a comma after the last item in an object or array. {"name": "John",} is invalid.

10. Common Mistakes

  • Forgetting to select "JSON" from the dropdown: If you leave the dropdown on "Text", Postman sends the Header Content-Type: text/plain. The server expects JSON, sees "text", and completely ignores your payload, leading to hours of frustrating debugging.
  • Using Single Quotes: In JavaScript, {'name': 'John'} is valid. In strict JSON, it is invalid. You MUST use double quotes: {"name": "John"}.

11. Mini Exercises

  1. 1. Look at this snippet: { "score": "100" }. Is the score a number or a string?
  1. 2. Find the syntax error in this JSON: {"user": "Admin", "role": "Super" "active": true}

12. Coding/Testing Challenges

Challenge 1: Create a POST request to https://jsonplaceholder.typicode.com/users. Construct a raw JSON body that includes a name (string), a username (string), and an address (which must be a nested JSON object containing city and zipcode). Hit Send and verify it returns 201 Created.

13. MCQs with Answers

Question 1

When sending raw JSON in Postman, what crucial step must you take in the Body tab to ensure the server understands the data?

Question 2

Which of the following is valid strict JSON syntax?

Question 3

If you need to upload a profile picture (.jpg) via an API, which Body format option should you select in Postman?

14. Interview Questions

  • Q: Explain the difference between raw JSON and form-data in a POST request.
  • Q: A developer complains that their POST request is returning a 400 Bad Request or 415 Unsupported Media Type error, even though their JSON looks perfect. What is the most likely mistake they made in Postman? *(Answer: They forgot to set the Content-Type header to application/json, likely by forgetting to change the Text dropdown to JSON).*

15. FAQs

Q: Can I send comments inside my JSON body in Postman? A: Strict JSON does not support comments (like // comment). If you put them in, Postman will highlight them as an error. However, some lenient backend servers might process them anyway. It is best practice to remove all comments before sending.

16. Summary

In this chapter, we learned how to package and send data using the Request Body. We mastered the strict syntax rules of JSON—emphasizing double quotes and proper comma placement. We walked through the critical process of configuring Postman's Body tab using the raw and JSON settings to ensure our data is sent with the correct Content-Type header. We also touched on alternative body formats like form-data for file uploads.

17. Next Chapter Recommendation

You now know how to build a perfect request. But how do you interpret what the server yells back at you when things go wrong? Proceed to Chapter 9: Understanding API Responses and Status Codes to decode the secret language of HTTP responses.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·