Here you go: a proven solution based on answer from @Brien
This should be able to handle any arbitrary size of the input file. This is a generator, so it leads to the creation of dictionary objects one at a time, since it parses them from the input JSON file.
If you run it as standalone, it runs three test cases. (In the if __name__ == "__main__" block)
Of course, to make it read from standard input, you simply pass sys.stdin as an argument to the input file.
import json _DECODER = json.JSONDecoder() _DEFAULT_CHUNK_SIZE = 4096 _MB = (1024 * 1024) _LARGEST_JSON_OBJECT_ACCEPTED = 16 * _MB
source share