Need Assistance?

support@tutorialshub.in

Exceptions and File Handling

Reading and writing files

ADVERTISEMENT
Python Free Lesson
5 min read
ADVERTISEMENT

JSON as an interchange format

JSON represents objects, arrays, strings, numbers, booleans and null. Python's json module converts between JSON text and corresponding Python values.

Serialization and parsing

json.dumps() converts a Python value to JSON text, while json.loads() parses JSON text. The file-oriented dump() and load() functions work directly with file objects.

Validate external data

Parsing JSON successfully does not mean the data is correct for your application. Check required keys, expected types and allowed values before using the data in business logic.

Practice: save a list of products as JSON, load it, update one product and write the result back with readable indentation.

ADVERTISEMENT