JSON is a commonly used data exchange format over the Web. For Python programming language, JSON data format is already very similar to Python dictionary, which makes parsing JSON in Python very convenient.
A handy Python module
json already exists for such purpose. For basic usage,
the most important methods are
dumps means dumping python object into JSON
loads is the reverse of
dumps, which loads JSON
into a Python object.
Here are some examples how you can use these two methods:
That’s it! This is how simple it is!
Be aware that JSON format only accepts double-quoted strings as its keys, and for its values, it accepts
only Number (
float), String (
unicode), Boolean (
False), Array (
dict) and Null (
That means just arbitrary Python objects cannot be turned into a JSON with
json.dumps; they need to be convered by
hand (with some codes) into combinations of the Python data types mentioned in the previous paragraph before feeding