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

support for ndjson #478

Open
pinkasey opened this issue Dec 18, 2022 · 0 comments
Open

support for ndjson #478

pinkasey opened this issue Dec 18, 2022 · 0 comments

Comments

@pinkasey
Copy link

It would be nice if the json middleware could support ndjson as well.
e.g, something like this as input:

{ "id": 1, "message": "hello" }
{ "id": 2, "message": "I'm a JSON inside a NDJSON" }

I've recently tried to consume a webhook of some big SaaS company, and they call the webhook with a POST and Content-Type: application/json (they should be passing Content-Type: application/x-ndjson).

From my perspective -
I didn't even know that ndjson exist until yesterday, and it's so similar to json - I would've hoped anything that can consume json can also consume ndjson. It's very easy to make that work.

What I had in mind -
add an option, something like allow_ndjson (default to false for backward compatibility), and if it's true -
when parsing a JSON fails, try splitting the body by \n, and parsing each part as json. return an array of the resulting jsons.
So the example above would result it:

[
  { "id": 1, "message": "hello" },
  { "id": 2, "message": "I'm a JSON inside a NDJSON" }
]

I'll be happy to contribute PR if there's a chance it would be approved.

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

No branches or pull requests

1 participant