-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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 JSON streaming formats besides application/stream+json #21283
Comments
Rossen Stoyanchev commented Indeed the "application/stream+json" seems to have originated from Activity Streams and is not the same as streaming JSON. Sébastien Deleuze do you have any further insight? Technically, we could stream via "application/json", effectively producing or consuming a JSON array. However it is useful for both client and server to differentiate between a finite array and a long running stream. Perhaps all we need is a custom parameter on "application/json"? Note that we have a similar question for streaming with Protobuf in #20331.
|
Sebastiaan van Erk commented I also checked application/json spec (https://tools.ietf.org/html/rfc4627) and the spec says that it must contain a valid JSON-text which is an object or an array according to the grammer defined in the RFC. Unfortunately a sequence of 2 json objects/arrays is not a valid JSON-text anymore. :( It's suprising to me that there isn't anything standard for this, seems like a very common use case. I've seen some attempts at standardization (e.g., http://ndjson.org/), but they don't seem to be used a lot. The ndjson seems nice (the fact that it allows any json value instead of only objects or arrays is nice), but I do find the single line per value rather restrictive. |
Sébastien Deleuze commented I agree that current mime type is not ideal. I am not sure about just using In fact there is an official RFC for JSON streams: JavaScript Object Notation (JSON) Text Sequences aka RFC7464 which defines Our current implementation supports both line-delimited JSON and concatenated JSON. As pointed out by Rossen Stoyanchev, we have similar question for Protobuf in #20331, but also for Smile streaming support introduced via #20699 and I am pretty sure that the question will arise for other formats as well. Even if it does not exist yet, I think a flexible solution would something like be a
Given So in a nutshell in this proposal, we would use One of the benefits of that approach is that we could implement streaming support in a generic way. Any thoughts? |
Sébastien Deleuze commented As suggested by Rossen Stoyanchev (we discussed that yesterday more in detail), another solution would be to serialize JSON streams as arrays since our JSON decoder is able to decode them in a streaming way too. That would make the output valid from a JSON POV (even if the closing bracket will never be reached for infinite streams), allow usage of Brian Clozel rightfully noticed that RFC7464 has been mainly introduced to help non streaming parser/encoder to support JSON streaming that were not widely available at the time the spec was introduced, so Spring WebFlux is maybe not the typical target for such support since we have streaming support out of the box. Based on this information, we can probably wait somebody has a real use case before supporting it. It seems we agree on deprecating Next step is deciding what parameter to use for JSON, Smile and Protobuf streaming. |
Sébastien Deleuze commented We have a working solution for Protobuf and no clear industry standard for JSON streaming yet, so I prefer to keep current arrangement for 5.1. |
Rossen Stoyanchev commented A few APIs use "application/json" but return line-delimited JSON data, e.g. Oanda and Flowdock. Neo4j API expects an JS client libraries support parsing in streaming mode. JSONStream takes a JSON path like |
Is there a decision if
|
@sdeleuze maybe we should take another look for 5.2? I see JSON Lines and ndjson (with |
Any decision made on this? FluentD f.e. defaults to ndjson now... |
Is there any update on this? What would be the best way to do JSON streaming right now? |
Scheduling tentatively for 5.3 M1 to try and add support for additional JSON streaming formats. We could also deprecate "application/stream+json". |
I've deprecated "application/stream+json" and added "application/x-ndjson". The latter is now also supported out of the box in the Jackson Encoder and Decoder. While it is not an officially registered media type, at least it's a common convention that seems to be in use while JSON lines doesn't even have that. There is also JSON Text Sequences and that is possible to use still with newline as the separator but "application/json-seq" would need to be registered with the Jackson Encoder and Decoder. As for separators other than newline, I'm not sure that Jackson's non-blocking parser supports that. In summary, use line-delimited JSON with "application/x-ndjson" supported as a media type out of the box and used as a replacement for "application/stream+json". Alternatively, register any other mime type and as long as it's a line-delimited JSON format it'll work the same. The mime type itself is just a convention for describing the format and as long as both sides understand it, it's enough. |
Sebastiaan van Erk opened SPR-16742 and commented
The mime type used by Spring Web Reactive for streaming json does not seem to be correct. The mime type "application/stream+json" is for an obsolete standard for activity streams:
https://tools.ietf.org/id/draft-snell-activity-streams-type-01.html
It has been superseded by the standard:
https://www.w3.org/TR/activitystreams-core/
with mime type "application/activity+json".
However, an activity stream is not the same as streaming json, so neither of these mime types should be used.
I was unable to find any standard mime type for json streaming, so I'm not sure what the resolution should be. The mime type should not be in the standards tree (since it is not a standard mime type), and the "x-" tree seems to be deprecated (since 1996) (see https://en.wikipedia.org/wiki/Media_type).
But I'm not sure that using a deprecated media type in the standards tree which is not officially registered, was invented for a different purpose, and has been superseded, is the way to go.
Affects: 5.0.5
Issue Links:
1 votes, 6 watchers
The text was updated successfully, but these errors were encountered: