Skip to content

Support for stream (equivalent to json.load/json.dump) #80

Closed

Description

@xavierhardy

We would like to be able to parse streams/file objects to avoid having to read first the entire stream and then parse it.

Activity

  1. lelit commented on Sep 22, 2017

    @lelit
    Contributor

    Yes.

    Ideally it should use the stream interface of Rapidjson, not sure if my C++ skill is up-to-the-task...

    As a fallback, I can easily add a load() function that accepts a file-like object and reads its content behind the scene...

  2. kenrobbins commented on Sep 29, 2017

    @kenrobbins
    Member

    That seems to be what the stdlib json and ujson do -- just pass f.read() into the loads().

    We could probably take advantage of RapidJSON's file stream class to operate on a file descriptor. Or maybe implement a custom RapidJSON stream object that would go between a Python file like object, but it seems like that could spend a lot of time in Python.

    @xavierhardy What is your use case? Is it actual files or other things?

  3. lelit commented on Sep 30, 2017

    @lelit
    Contributor

    Just for fun^H^H^Hlearning some more C++, I tried a few approaches, and this is currently the best outcome, that implements the custom stream (only for load() right now): it has tricky bugs and I didn't benchmark it.

    Anyway, I'm not sure I will be able to spend more time on that in the near future, and it surely needs some love before being considered for merge in master.

  4. added a commit that references this issue on Dec 22, 2017
  5. lelit commented on Dec 22, 2017

    @lelit
    Contributor

    A slightly better and more complete implementation here. All tests passes, but there are still some shortcomings: I'm not sure I will ever be able to fix them though.

  6. lelit commented on Dec 22, 2017

    @lelit
    Contributor
  7. lelit commented on Dec 24, 2017

    @lelit
    Contributor

    I was able to implement the text-based streaming and figured out how to configure the writer to support ensure_ascii=True. So the remaining issue seems to be the handling of possible errors while reading/writing the underlying stream.

  8. lelit commented on Dec 27, 2017

    @lelit
    Contributor

    I think I solved that last issue and everything seems going well, so barring possible objections I'm going to merge PR #92 in the first week of the new year, or so.
    Given that it changes the signature of existing loads() and dumps() functions (following stdlib json module the flags are now keyword only arguments), it will eventually land in version 0.4.

  9. lelit commented on Jan 5, 2018

    @lelit
    Contributor

    I just released v0.4 that implements this feature.
    Thank you!

  10. xavierhardy commented on Feb 10, 2018

    @xavierhardy
    Author

    Great! Thanks a lot!

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions