# Json Notes

## Json.load(s)

`load` 读入需要**文件流**

```python
import json
with open('test.json', 'r') as f:
    js_file = json.load(f)
```

`loads` 读入需要**字符串**

```python
import json
js_file = json.loads("{"1":"first", "2":"second", "3":"third"}")
```

## Json.dumps

`dumps`为json格式的导出，以下列出了几个常见的参数：

```python
with open("courses.json", "w", encoding='utf-8') as f:
    f.write(str(json.dumps(total_list, indent=4, ensure_ascii=False)))
```

其中打开文件时`encoding='utf-8'`和dumps时`ensure_ascii=False`为保证导出的json中的**中文格式编码正常**。\
其中`indent=4`是设置json格式的缩紧空格个数。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://legacy.cookielau.com/archives/3-python/2-library/3-jsonnotes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
