---
title: "Explain the Python JSON"  
description: "Explain the Python JSON"  
author: "ICSM Computer"  
published: 2025-10-12  
updated: 2025-11-10  
canonical: https://www.mindstick.com/interview/34389/explain-the-python-json  
category: "python"  
tags: ["python-3.4", "Python 3"]  
reading_time: 4 minutes  

---

# Explain the Python JSON

> **JSON** stands for [**JavaScript Object Notation**](https://www.mindstick.com/forum/161052/explain-json-vs-javascript-object-explanation).\
> It’s a **lightweight data format** used for exchanging data between systems — often between a **client (browser)** and a **server (backend)**.

- It’s easy for humans to read and write.
- It’s easy for machines to parse and generate.
- It looks very similar to Python dictionaries!

## Example of JSON:

```plaintext
{
  "name": "Anna",
  "age": 25,
  "skills": ["Python", "C#", "SQL"],
  "isDeveloper": true
}
```

### JSON in Python

Python provides a built-in module called `json` to work with **JSON data**.

You can use it to:

- **Convert Python objects → JSON string**
- **Convert JSON string → Python objects**

### 1. Convert Python object to JSON string

Use `json.dumps()`

```python
import json

data = {
    "name": "Anna",
    "age": 25,
    "skills": ["Python", "C#", "SQL"]
}

json_string = json.dumps(data)
print(json_string)
```

## Output:

```plaintext
{"name": "Anna", "age": 25, "skills": ["Python", "C#", "SQL"]}
```

> `dumps` → “dump string” (convert to JSON string)

### 2. Convert JSON string to Python object

Use `json.loads()`

```python
import json

json_data = '{"name": "Anna", "age": 25, "skills": ["Python", "C#", "SQL"]}'

python_obj = json.loads(json_data)
print(python_obj)
print(python_obj["name"])
```

## Output:

```plaintext
{'name': 'Anna', 'age': 25, 'skills': ['Python', 'C#', 'SQL']}
Anna
```

> `loads` → “load string” (convert to Python object)

### 3. Read/Write JSON file

## Write to file:

```python
import json

data = {"name": "Anna", "age": 25}

with open("data.json", "w") as file:
    json.dump(data, file)
```

## Read from file:

```python
with open("data.json", "r") as file:
    result = json.load(file)
    print(result)
```

> `dump` and `load` are for file operations (not strings).

### Supported Data Types

| Python Type | JSON Type |
| --- | --- |
| dict | object |
| list, tuple | array |
| str | string |
| int, float | number |
| True | true |
| False | false |
| None | null |

### Extra Tip – Pretty Print JSON

You can make JSON output more readable using `indent`:

```python
print(json.dumps(data, indent=4))
```

## Output:

```plaintext
{
    "name": "Anna",
    "age": 25
}
```

## Answers

### Answer by ICSM Computer

> **JSON** stands for [**JavaScript Object Notation**](https://www.mindstick.com/forum/161052/explain-json-vs-javascript-object-explanation).\
> It’s a **lightweight data format** used for exchanging data between systems — often between a **client (browser)** and a **server (backend)**.

- It’s easy for humans to read and write.
- It’s easy for machines to parse and generate.
- It looks very similar to Python dictionaries!

## Example of JSON:

```plaintext
{
  "name": "Anna",
  "age": 25,
  "skills": ["Python", "C#", "SQL"],
  "isDeveloper": true
}
```

### JSON in Python

Python provides a built-in module called `json` to work with **JSON data**.

You can use it to:

- **Convert Python objects → JSON string**
- **Convert JSON string → Python objects**

### 1. Convert Python object to JSON string

Use `json.dumps()`

```python
import json

data = {
    "name": "Anna",
    "age": 25,
    "skills": ["Python", "C#", "SQL"]
}

json_string = json.dumps(data)
print(json_string)
```

## Output:

```plaintext
{"name": "Anna", "age": 25, "skills": ["Python", "C#", "SQL"]}
```

> `dumps` → “dump string” (convert to JSON string)

### 2. Convert JSON string to Python object

Use `json.loads()`

```python
import json

json_data = '{"name": "Anna", "age": 25, "skills": ["Python", "C#", "SQL"]}'

python_obj = json.loads(json_data)
print(python_obj)
print(python_obj["name"])
```

## Output:

```plaintext
{'name': 'Anna', 'age': 25, 'skills': ['Python', 'C#', 'SQL']}
Anna
```

> `loads` → “load string” (convert to Python object)

### 3. Read/Write JSON file

## Write to file:

```python
import json

data = {"name": "Anna", "age": 25}

with open("data.json", "w") as file:
    json.dump(data, file)
```

## Read from file:

```python
with open("data.json", "r") as file:
    result = json.load(file)
    print(result)
```

> `dump` and `load` are for file operations (not strings).

### Supported Data Types

| Python Type | JSON Type |
| --- | --- |
| dict | object |
| list, tuple | array |
| str | string |
| int, float | number |
| True | true |
| False | false |
| None | null |

### Extra Tip – Pretty Print JSON

You can make JSON output more readable using `indent`:

```python
print(json.dumps(data, indent=4))
```

## Output:

```plaintext
{
    "name": "Anna",
    "age": 25
}
```


---

Original Source: https://www.mindstick.com/interview/34389/explain-the-python-json

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
