Forum > Windows

[solved]fcl-json and newlines

<< < (2/2)

Thaddy:
And that link is the ONLY reputable JSON doc, btw... Everything else is bolt-on rubbish.
I wrote a grammar for the real standard that can output Pascal. Many implementations use that as core.
It is on Embarcadero.

dbannon:
> Not really. here: https://www.json.org/json-en.html

And nicely written too. Better than the resources I have been using.  But still not totally clean about newline IMHO. While it mentions LineFeed and CarriageReturn it also says -

The Unicode code point U+000A is used as the newline.

Embedding "\u000A" instead of "\n" produces the same result, just a LineFeed on Windows

Thaddy, your JSON parser, made for Windows (or Delphi), did it convert "newline" to #10 or #13#10 on Windows ?

Davo

EDIT: OK, I give up, JSON Tools does the same thing, so right or wrong, thats how it it is !

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$ifdef WINDOWS}St := St.replace('#10', '#13#10', [rfReplaceAll]);{$endif} :D

Thausand:

--- Quote from: dbannon on May 15, 2022, 02:12:18 am ---While it mentions LineFeed and CarriageReturn it also says -
The Unicode code point U+000A is used as the newline.

--- End quote ---
Maybe you can help ? Because /me can not find it  :-[

"Newline" not exist for json.

ECMA document (https://www.ecma-international.org/wp-content/uploads/ECMA-404_2nd_edition_december_2017.pdf) writes:

--- Quote ---9 String
A string is a sequence of Unicode code points wrapped with quotation marks (U+0022). All code points may be placed within the quotation marks except for the code points that must be escaped: quotation mark
(U+0022), reverse solidus (U+005C), and the control characters U+0000 to U+001F. There are two-character escape sequence representations of some characters.
\" represents the quotation mark character (U+0022).
\\ represents the reverse solidus character (U+005C).
\/ represents the solidus character (U+002F).
\b represents the backspace character (U+0008).
\f represents the form feed character (U+000C).
\n represents the line feed character (U+000A).
\r represents the carriage return character (U+000D).
\t represents the character tabulation character (U+0009).
So, for example, a string containing only a single reverse solidus character may be represented as "\\".

--- End quote ---

json \n (Line feed) <> c \n (newline).

Newline is afaik c-ishm and platform depending, see https://en.wikipedia.org/wiki/Newline#In_programming_languages


--- Quote ---Embedding "\u000A" instead of "\n" produces the same result, just a LineFeed on Windows

--- End quote ---
Yes, see pdf ecma: it be linefeed.

I not know how to explain better (my English is bit better but not good). I think you wish for \n be JSON newline (I understand why) but that create same problem for JSON that is there for newline (example: TStringlist platform compatibility when read/write text lines). TStringlist solve problem but TStringlist is Pascal class and developer can make rules. JSON is official standard and developer have to follow (or fork/make new standard  :D )

dbannon:

--- Quote from: Thausand on May 15, 2022, 03:30:41 am ---Maybe you can help ? Because /me can not find it  :-[
"Newline" not exist for json.

--- End quote ---
From the link you posted, down right hand side, click on any of the entries under "escapes" and it takes you to https://www.crockford.com/mckeeman.html - not far down from the top.  But I suspect its not expressly about JS


--- Quote ---...see https://en.wikipedia.org/wiki/Newline#In_programming_languages

--- End quote ---
Java, PHP, and Python provide the '\r\n' sequence (for ASCII CR+LF). In contrast to C, these are guaranteed to represent the values U+000D and U+000A, respectively.
I am convinced !  I always considered a Java \n pretty much the same as a C one and therefore JS also the same, but I was wrong !


--- Quote ---I not know how to explain better (my English is bit better but not good).

--- End quote ---
You have made yourself quite understandable, far, far better than I would be in your native language !

Thanks

Thausand:

--- Quote from: dbannon on May 15, 2022, 09:57:23 am ---From the link you posted, down right hand side, click on any of the entries under "escapes" and it takes you to https://www.crockford.com/mckeeman.html - not far down from the top.  But I suspect its not expressly about JS

--- End quote ---
Thank you, light is now on  :)

not expressly = not explicit ?

If yes, then in first line of link it write:

--- Quote ---McKeeman Form
This is an excerpt from Chapter 22 of How JavaScript Works.

--- End quote ---
Later/down it write about JSON.


--- Quote ---This is the JSON grammar in McKeeman Form.

--- End quote ---

Hope it helped.

Navigation

[0] Message Index

[*] Previous page

Go to full version