eolas/zk/Working_with_JSON_in_Python.md
2024-10-18 19:00:03 +01:00

701 B

id tags created
mjia
python
JSON
Tuesday, June 25, 2024

Working with JSON in Python

json.loads()

Convert a string containing JSON data into the native Python dictionary object. Equivalent to JSON.parse() in JavaScript.

Will error if the input string is not properly formatted JSON. This will be json.JSONDecodeError, a subclass of the ValueError exception

json.dumps()

Take a JSON-formatted dictionary and convert it into a string. The reverse of json.loads() and equivalent to JSON.stringify() in JavaScript.

JSON errors

The .loads() and .parse() methods will throw an error if the input string is