Lesson 39 of 158 – Postman JSON Data
39%

Postman JSON Data

JSON (JavaScript Object Notation) is one of the most common formats used to send and receive data through REST APIs. In Postman, JSON can be used to test POST, PUT, and PATCH requests.

Note: JSON data is especially important when building React Native applications because mobile apps commonly communicate with REST APIs using JSON.

1. What is JSON?

JSON stands for JavaScript Object Notation. It is a lightweight text format used for storing and exchanging data.

Example:

{
    "name": "Rahul",
    "course": "ADCA"
}

2. Why APIs Use JSON

REST APIs commonly use JSON because it is easy for both humans and programming languages to read and process.

A server can send JSON to a React Native application, and the application can convert that data into objects that it can use.

3. JSON Object

A JSON object is enclosed inside curly braces:

{ }

It contains data in the form of key-value pairs.

{
    "name": "Amit",
    "age": 22
}

4. JSON Key and Value

A JSON property contains a key and a value separated by a colon.

{
    "name": "Amit"
}

Here:

  • name is the key.
  • Amit is the value.

5. JSON Strings

String values are written inside double quotation marks.

{
    "name": "Rahul Kumar",
    "course": "Python"
}

Both Rahul Kumar and Python are strings.

6. JSON Numbers

JSON can also contain numeric values.

{
    "age": 21,
    "fee": 5000
}

Numbers do not need quotation marks.

7. JSON Boolean Values

JSON supports the Boolean values true and false.

{
    "active": true,
    "verified": false
}

Boolean values are not written inside quotation marks.

8. JSON Null Value

JSON also supports the null value.

{
    "middle_name": null
}

Null can represent the absence of a value.

9. JSON Arrays

A JSON array is enclosed in square brackets.

[
    "HTML",
    "CSS",
    "JavaScript"
]

Arrays are useful when multiple values need to be represented.

10. JSON Array of Objects

A JSON array can contain multiple objects.

[
    {
        "id": 1,
        "name": "Rahul"
    },
    {
        "id": 2,
        "name": "Priya"
    }
]

This format is commonly returned by APIs that provide lists of records.

11. JSON in Postman

Postman allows us to enter JSON data when testing APIs.

For example, a POST request can send a new student as JSON.

{
    "name": "Rahul",
    "course": "ADCA"
}

12. Open the Body Section

To send JSON data in Postman:

  1. Select the required HTTP method.
  2. Open the Body tab.
  3. Select raw.
  4. Select JSON.
  5. Enter your JSON data.

13. Select raw

In the Body section, select the raw option.

This provides a text editor where you can directly enter JSON data.

{
    "name": "Amit",
    "course": "Java"
}

14. Select JSON Format

After selecting raw, choose JSON from the format dropdown.

This tells Postman that the request body is JSON data.

JSON

15. Example Student JSON

Suppose we want to add a student using a POST request.

{
    "name": "Rahul Kumar",
    "course": "ADCA",
    "mobile": "9876543210",
    "fee": 5000
}

This JSON contains four properties.

16. JSON Commas

Multiple JSON properties are separated using commas.

Correct example:

{
    "name": "Rahul",
    "course": "ADCA",
    "fee": 5000
}

A missing comma can make the JSON invalid.

17. JSON Double Quotes

JSON property names and string values use double quotation marks.

Correct:

{
    "name": "Rahul"
}

Always use valid JSON syntax when sending data through Postman.

18. Content-Type for JSON

When sending JSON data, the Content-Type header is commonly:

Content-Type: application/json

This tells the server that the request body contains JSON data.

19. JSON with POST

POST requests can use JSON to send new information to an API.

POST
http://localhost/api/students.php

{
    "name": "Amit",
    "course": "Python"
}

20. JSON with PUT

PUT requests can use JSON to send complete updated information for an existing resource.

PUT
http://localhost/api/students.php?id=10

{
    "name": "Amit Kumar",
    "course": "Java",
    "mobile": "9876543210"
}

21. JSON with PATCH

PATCH requests can use JSON to send only the fields that need to be changed.

PATCH
http://localhost/api/students.php?id=10

{
    "course": "React Native"
}

Only the specified field needs to be updated by an API designed for partial updates.

22. JSON Response from API

APIs can also return JSON data in their responses.

{
    "status": true,
    "message": "Student added successfully",
    "student_id": 15
}

Postman displays the JSON response after the request is completed.

23. JSON Array Response

An API that returns multiple records may send a JSON array.

[
    {
        "id": 1,
        "name": "Rahul",
        "course": "ADCA"
    },
    {
        "id": 2,
        "name": "Priya",
        "course": "Python"
    }
]

24. JSON Validation in Postman

Before sending a request, check that the JSON is correctly formatted.

Check:

  • Opening and closing braces
  • Quotation marks
  • Commas
  • Colons
  • Correct value types
  • Valid JSON structure

25. Invalid JSON Example

The following JSON is invalid because there is no comma between the properties:

{
    "name": "Rahul"
    "course": "ADCA"
}

The correct version is:

{
    "name": "Rahul",
    "course": "ADCA"
}

26. JSON Data Types

JSON supports several important data types:

  • String
  • Number
  • Boolean
  • Object
  • Array
  • Null

Understanding these types is important when working with API requests and responses.

27. JSON and React Native

React Native applications commonly receive JSON data from REST APIs.

REST API
    ↓
JSON Response
    ↓
React Native
    ↓
Display Data

JSON therefore forms an important connection between the backend API and the mobile application.

28. Complete JSON POST Example

Method:

POST

URL:

http://localhost/api/students.php

Body → raw → JSON:

{
    "name": "Amit Kumar",
    "course": "React Native",
    "mobile": "9876543210"
}

Click Send to send the JSON data to the API.

29. Complete JSON Response Example

The API can return a JSON response such as:

{
    "status": true,
    "message": "Student added successfully",
    "data": {
        "id": 15,
        "name": "Amit Kumar",
        "course": "React Native"
    }
}

Postman displays this response so that we can inspect the API result.

30. Postman JSON Data Summary

JSON is one of the most important data formats used with REST APIs. In Postman, JSON can be entered in the Body section using the raw and JSON options.

Postman
   ↓
HTTP Request
   ↓
JSON Data
   ↓
REST API
   ↓
JSON Response
   ↓
React Native App

📌 Key Points

  • JSON stands for JavaScript Object Notation.
  • JSON is commonly used with REST APIs.
  • JSON contains key-value pairs.
  • JSON supports strings, numbers, booleans, arrays, objects, and null.
  • Postman can send JSON data through the Body section.
  • Select raw and JSON when sending JSON request data.
  • Content-Type is commonly application/json for JSON requests.
  • POST can use JSON to create new resources.
  • PUT can use JSON to update resources.
  • PATCH can use JSON to partially update resources.
  • REST APIs can also return JSON responses.
  • React Native applications commonly consume JSON API responses.

🧠 Quick Quiz

Question: Which option should normally be selected in Postman's Body section when you want to send JSON data?