You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
It would be nice if the
json
middleware could support ndjson as well.e.g, something like this as input:
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 passingContent-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 tofalse
for backward compatibility), and if it'strue
-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:
I'll be happy to contribute PR if there's a chance it would be approved.
The text was updated successfully, but these errors were encountered: