Minor JSON output bug (infinity)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Minor JSON output bug (infinity)

Alexander Beedie
Test-case / repro:
“SELECT JSON_ARRAY(1e9999,-1e9999,NULL)”

Actual output:
‘[Inf,-Inf,null]’

Expected output:
‘[Infinity,-Infinity,null]’

All JSON parsers I have tried fail on “Inf”, but the majority will succeed with “Infinity” (as this is the standard JS property name)

eg: in standard python -

>> import json
>> json.loads( ‘[Inf,-Inf,null]’ )
ValueError: No JSON object could be decoded
>> json.loads( ‘[Infinity,-Infinity,null]’ )
[inf, -inf, None]


Regards,

-Alex
--
iPhoneから送信
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Minor JSON output bug (infinity)

Richard Hipp-3
On 1/22/18, Alexander Beedie <[hidden email]> wrote:

> Test-case / repro:
> “SELECT JSON_ARRAY(1e9999,-1e9999,NULL)”
>
> Actual output:
> ‘[Inf,-Inf,null]’
>
> Expected output:
> ‘[Infinity,-Infinity,null]’
>
> All JSON parsers I have tried fail on “Inf”, but the majority will succeed
> with “Infinity” (as this is the standard JS property name)

A strict reading of https://json.org/ suggests that neither "Inf" nor
"Infinity" ought to work.  I'm not sure how we ought to deal with
this....

>
> eg: in standard python -
>
>>> import json
>>> json.loads( ‘[Inf,-Inf,null]’ )
> ValueError: No JSON object could be decoded
>>> json.loads( ‘[Infinity,-Infinity,null]’ )
> [inf, -inf, None]
>
>
> Regards,
>
> -Alex
> --
> iPhoneから送信
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Minor JSON output bug (infinity)

J. King-3
In reply to this post by Alexander Beedie
RFC 8259 states:

> Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.

This is one of the cases that expose the fallacy of the "JS" part of "JSON". While SQLite should not be producing Inf as a bare word, it should not be producing Infinity, either, as a conforming parser would reject both.

What to do in such a case is undefined, but for the stated case there is actually a very sensible conforming output:

'[1e9999,-1e9999,null]'

I realize it is impractical for SQLite to do so, but given that JSON numbers convey arbitrary precision, only explicit infinity should, ideally, result in undefined behaviour.

On January 22, 2018 9:00:35 PM EST, Alexander Beedie <[hidden email]> wrote:

>Test-case / repro:
>“SELECT JSON_ARRAY(1e9999,-1e9999,NULL)”
>
>Actual output:
>‘[Inf,-Inf,null]’
>
>Expected output:
>‘[Infinity,-Infinity,null]’
>
>All JSON parsers I have tried fail on “Inf”, but the majority will
>succeed with “Infinity” (as this is the standard JS property name)
>
>eg: in standard python -
>
>>> import json
>>> json.loads( ‘[Inf,-Inf,null]’ )
>ValueError: No JSON object could be decoded
>>> json.loads( ‘[Infinity,-Infinity,null]’ )
>[inf, -inf, None]
>
>
>Regards,
>
>-Alex
>--
>iPhoneから送信
>_______________________________________________
>sqlite-users mailing list
>[hidden email]
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Minor JSON output bug (infinity)

J Decker
In reply to this post by Alexander Beedie
On Mon, Jan 22, 2018 at 6:00 PM, Alexander Beedie <
[hidden email]> wrote:

> Test-case / repro:
> “SELECT JSON_ARRAY(1e9999,-1e9999,NULL)”
>
> Actual output:
> ‘[Inf,-Inf,null]’
>
> Expected output:
> ‘[Infinity,-Infinity,null]’
>
> All JSON parsers I have tried fail on “Inf”, but the majority will succeed
> with “Infinity” (as this is the standard JS property name)
>
JSON5 or JSON6 handle it.
http://json5.org/  https://github.com/d3x0r/json6  (
https://github.com/d3x0r/SACK/blob/master/src/netlib/html5.websocket/json/json6_parser.c
)

(also NaN)
but yes that is a deficiency in JSON.


> eg: in standard python -
>
> >> import json
> >> json.loads( ‘[Inf,-Inf,null]’ )
> ValueError: No JSON object could be decoded
> >> json.loads( ‘[Infinity,-Infinity,null]’ )
> [inf, -inf, None]
>
>
> Regards,
>
> -Alex
> --
> iPhoneから送信
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users