#!! Serialization and deserialization are not perfectly inverse operations !!
##SERIALIZE
### Python -> JSON
#dumps()—to serialize an object to a JSON formatted string (useful for printing the output)
#dump()—to serialize an object to a JSON formatted stream (which supports writing to a file).
#serialized python data
with open("data_file.json", "w") as write_file:
json.dump(data, write_file, indent = 4) #indent sets number of spaces to indent
json_str = json.dumps(data, indent = 4) #indent sets number of spaces to indent
print(json_str)
#DESERIALIZE
### JSON -> Python
#loads()—to deserialize a JSON document to a Python object. (prints out results)
#load()—to deserialize a JSON formatted stream (which supports reading from a file) to a Python object.
#For example, a Python tuple will be serialized as a JSON array. When we deserialize the array, we will get a Python list containing the data in the tuple. If we want our original tuple object back, we need to pass this list into the initializer for the tuple.