Python Pages Doc Ic Ac Uk CPP Lessons CPP 10 Files 04 Dump HTML
Python Pages Doc Ic Ac Uk CPP Lessons CPP 10 Files 04 Dump HTML
Conversely, you can also easily write a Python object to a JSON string. The fancy term is serialisation
(converting a data object into a string representation, usually for storage or transmission).
To write your data into a JSON file, use json.dump(). The following code serialises data to JSON format and saves it
in a file called output.json.
import json
To write your data to a string (and do something else with it later), use json.dumps().
json_string = json.dumps(data)
print(json_string) # {"course": "Introduction to Machine Learning", "term": 1}
Previous Next