JSON
JavaScript Object Notation (JSON) is a common format used to transfer data over the internet. The JSON specification can be found at https://www.json.org. Despite the name, it does not require JavaScript to read or create.
The Python standard library ships with the json
library, which can serialize and deserialize Python objects to/from JSON:
import json
beatles = {
"first": ["Paul", "John", "Richard", "George",],
"last": ["McCartney", "Lennon", "Starkey", "Harrison",],
"birth": [1942, 1940, 1940, 1943],
}
serialized = json.dumps(beatles)
print(f"serialized values are: {serialized}")
deserialized = json.loads(serialized)
print(f"deserialized values are: {deserialized}")
serialized values are: {"first": ["Paul", "John", "Richard", "George"], "last": ["McCartney...