[aur-dev] Absence of terminating newline in RPC requests
JSON from the RPC interface seems to not contain a terminating newline, regardless of version or type specified. I am curious if there is a particular reason for this, as the POSIX standard defines text files to contain lines with terminating newlines. [1] [2] This is more noticeable when merging the resulting files to a valid JSON structure, e.g. to display the union of various search results. As a comparison, journalctl - json does terminate lines with a newline. Regards, Alad [1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_... [2] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_...
Hey, On 22/09, Alad Wenter wrote:
JSON from the RPC interface seems to not contain a terminating newline, regardless of version or type specified. I am curious if there is a particular reason for this, as the POSIX standard defines text files to contain lines with terminating newlines. [1] [2]
This is more noticeable when merging the resulting files to a valid JSON structure, e.g. to display the union of various search results. As a comparison, journalctl - json does terminate lines with a newline.
The RPC just returns whatever json_encode gave it, and doesn't do anything manual to the data returned. (And they're not actually files at any stage, so what POSIX wants doesn't matter much. ;)) Anyway, we could definitely add it, but every json tool should definitely be able to handle them as it is. Examples of ones that don't? -- Sincerely, Johannes Löthberg PGP Key ID: 0x50FB9B273A9D0BB5 https://theos.kyriasis.com/~kyrias/
Johannes Löthberg via aur-dev schreef op 2016-09-22 20:23:
Hey,
On 22/09, Alad Wenter wrote:
JSON from the RPC interface seems to not contain a terminating newline, regardless of version or type specified. I am curious if there is a particular reason for this, as the POSIX standard defines text files to contain lines with terminating newlines. [1] [2]
This is more noticeable when merging the resulting files to a valid JSON structure, e.g. to display the union of various search results. As a comparison, journalctl - json does terminate lines with a newline.
The RPC just returns whatever json_encode gave it, and doesn't do anything manual to the data returned. (And they're not actually files at any stage, so what POSIX wants doesn't matter much. ;))
Anyway, we could definitely add it, but every json tool should definitely be able to handle them as it is. Examples of ones that don't?
True, I haven't had issues with json tools regarding a (lack of) terminating newlines. Some tools like jshon do have an issue with several requests pasted together, unless you insert some commas. In that sense I wondered on how the RPC terminates its output, and how it may do so in the future. Of course, if/when we get POST requests [1], you no longer have to think on merging JSON. :) Thanks, Alad [1] https://bugs.archlinux.org/task/49089
On 01/10, Alad Wenter wrote:
True, I haven't had issues with json tools regarding a (lack of) terminating newlines. Some tools like jshon do have an issue with several requests pasted together, unless you insert some commas. In that sense I wondered on how the RPC terminates its output, and how it may do so in the future.
Of course, if/when we get POST requests [1], you no longer have to think on merging JSON. :)
Mmmm. It's very common for JSON libraries, see eg. Jansson, to not add a newline because it's easier for the consumer to add one if necessary than it is to reliably remove one. I wouldn't personally mind having it add one, but at the same time I don't see much of a reason to implement it either. On a related note, it would be nice to rewrite the RPC, because it's a bit weird code. -- Sincerely, Johannes Löthberg PGP Key ID: 0x50FB9B273A9D0BB5 https://theos.kyriasis.com/~kyrias/
participants (2)
-
Alad Wenter
-
Johannes Löthberg