Skip to content

Feature request: streaming pretty-print output #61

Description

@yairlenga

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);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions