Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add msgspec.json.Encoder.encode_lines #479

Merged
merged 1 commit into from
Jul 11, 2023
Merged

Add msgspec.json.Encoder.encode_lines #479

merged 1 commit into from
Jul 11, 2023

Conversation

jcrist
Copy link
Owner

@jcrist jcrist commented Jul 11, 2023

This adds a new method on the JSON Encoder class for encoding an iterable of items as newline delimited JSON, one item per line. This is roughly equivalent to (but up to 3x faster than):

def encode_lines(items):
    return b''.join(
        msgspec.json.encode(item) + b'\n' for item in items
    )

We limit it to an implementation on the Encoder class alone for now (rather than a new top-level function) since this is a relatively niche feature.

Fixes #449.

This adds a new method on the JSON `Encoder` class for encoding an
iterable of items as newline delimited JSON, one item per line. This is
roughly equivalent to (but up to 3x faster than):

```
def encode_lines(items):
    return b''.join(
        msgspec.json.encode(item) + b'\n' for item in items
    )
```

We limit it to an implementation on the `Encoder` class alone for now
(rather than a new top-level function) since this is a relatively niche
feature.
@jcrist jcrist merged commit 473d6d3 into main Jul 11, 2023
@jcrist jcrist deleted the json-encode-lines branch July 11, 2023 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for JSON lines (JSON line-delimited)
1 participant