I am writing a program, which requires me to generate a very large json
file. I know the traditional way is to dump a dictionary list using json.dump()
Sadly the json
library does not have any incremental writing facilities, and therefore cannot do what you want.
That's clearly going to be a very large file - would some other representation be more appropriate?
Otherwise the best suggestion I can make is to dump each list entry to an in-memory structure and write them out with the necessary delimiters ([
at the beginning, ],[
between entries and ]
at the end) to try and construct the JSON that you need.
If formatting is important you should know that the wrapper test your program writes will destroy correct indentation, but indentation is only for humans so it shouldn't make any difference to the semantics of the JSON structure.