JSON streaming

Uses your system voice; voice and rate in settings.

Snapshot

≈ 3 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

JSON streaming comprises communications protocols to delimit JSON objects built upon lower-level stream-oriented protocols (such as TCP), that ensures individual JSON objects are recognized, when the server and clients use the same one (e.g. implicitly coded in). This is necessary as JSON is a non-concatenative protocol (the concatenation of two JSON objects does not produce a valid JSON object). IETF defines a JSON text sequence as JSON texts each preceded by the ASCII record separator character and followed by a line feed.

JSON streaming comprises communications protocols to delimit JSON objects built upon lower-level stream-oriented protocols (such as TCP), that ensures individual JSON objects are recognized, when the server and clients use the same one (e.g. implicitly coded in). This is necessary as JSON is a non-concatenative protocol (the concatenation of two JSON objects does not produce a valid JSON object). IETF defines a JSON text sequence as JSON texts each preceded by the ASCII record separator character and followed by a line feed. {"some":"thing\n"} {"may":{"include":"nested","objects":["and","arrays"]}} The use of a newline as a delimiter enables this format to work very well with traditional line-oriented Unix tools. A log file, for example, might look like: {"ts":"2020-06-18T10:44:12","started":{"pid":45678}} {"ts":"2020-06-18T10:44:13","logged_in":{"username":"foo"},"connection":{"addr":"1.2.3.4","port":5678}} {"ts":"2020-06-18T10:44:15","registered":{"username":"bar","email":"bar@example.com"},"connection":{"addr":"2.3.4.5","port":6789}} {"ts":"2020-06-18T10:44:16","logged_out":{"username":"foo"},"connection":{"addr":"1.2.3.4","port":5678}} which is very easy to sort by date, grep for usernames, actions, IP addresses, etc. jq --compact-output . lines.json ␞{"some":"thing\n"}␊ ␞{ "may": { "include": "nested", "objects": [ "and", "arrays" ] } }␊ {"some":"thing\n"}{"may":{"include":"nested","objects":["and","arrays"]}} { "some": "thing\n" } { "may": { "include": "nested", "objects": [ "and", "arrays" ] } } Implementations that rely on line-based input may require a newline character after each JSON object in order for the object to be emitted by the parser in a timely manner. (Otherwise the line may remain in the input buffer without being passed to the parser.) This is rarely recognised as an issue because terminating JSON objects with a newline character is very common. This example shows two length-prefixed JSON objects (with each length being the byte-length of the following JSON string): 18{"some":"thing\n"}55{"may":{"include":"nested","objects":["and","arrays"]}}

Text derived from https://en.wikipedia.org/w/index.php?oldid=1367461180 under CC BY-SA 4.0; modifications have been made.

Sources cited in this revision

13 named source(s) extracted from the cited revision. A source with no author is shown by its publication; nothing is invented.