Alternatively, you could create a file with contents [1, 2, 3] and read it to know the expected output: import json with open("example1.json", "r") as ex1_file: ex1 = ex1_file.read().rstrip() assert(json.dumps([1,2,3]) == ex1) The file example1.json is called a golden file. Here are some advantages of golden tests over ordinary unit tests: If the expected output is large in size, it may be impract