Python JSON tricks: how to deal with JSONDecodeError
A trick you may not know yet
JSON (JavaScript Object Notation) is a standard data format that uses human-readable text to store and transmit data objects consisting of attribute-value pairs and array data types. It is a very common data format with a diverse range of applications, especially in web development.
A JSON looks like the dictionary type in Python, but they are different. The essential difference is that a JSON is a pure string that has a strict format. If you don’t write it properly, you may have unexpected errors.
In this statement, student_dict
is a valid Python dictionary, but it is not a JSON. To convert a Python dictionary to a JSON, you can use the dumps
method of the json
module: