Skip to content

Commit 1efbf92

Browse files
authored
Simplify json load/dump usage
1 parent a03c8dc commit 1efbf92

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/cheatsheet/json-yaml.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ JSON stands for JavaScript Object Notation and is a lightweight format for stori
1212
```python
1313
>>> import json
1414
>>> with open("filename.json", "r") as f:
15-
... content = json.loads(f.read())
15+
... content = json.load(f)
1616
```
1717

1818
Write a JSON file with:
@@ -22,7 +22,7 @@ Write a JSON file with:
2222

2323
>>> content = {"name": "Joe", "age": 20}
2424
>>> with open("filename.json", "w") as f:
25-
... f.write(json.dumps(content, indent=2))
25+
... json.dump(content, f, indent=2)
2626
```
2727

2828
## YAML

0 commit comments

Comments
 (0)