I'm working with large JSON documents and would like to stream them to filehandle or socket without constructing the entire formatted string in memory.
Currently, output (regular and pretty-printed) appears to be generated by building strings and returning the final result. I'm wondering whether there would be interest in a streaming API that writes formatted JSON incrementally to a filehandle.
The motivation is:
- lower peak memory usage
- immediate time-to-first-byte
- support for very large JSON documents
I've been experimenting with a prototype formatter and would be happy to share ideas or contribute if this is something that might fit the project.
Would such a feature be of interest?
Possible API shapes could be something like encode_to, which can return the number of characters written, or undef on error.
$json->encode_to($fh, $data);
I'm working with large JSON documents and would like to stream them to filehandle or socket without constructing the entire formatted string in memory.
Currently, output (regular and pretty-printed) appears to be generated by building strings and returning the final result. I'm wondering whether there would be interest in a streaming API that writes formatted JSON incrementally to a filehandle.
The motivation is:
I've been experimenting with a prototype formatter and would be happy to share ideas or contribute if this is something that might fit the project.
Would such a feature be of interest?
Possible API shapes could be something like
encode_to, which can return the number of characters written, or undef on error.