This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: json traceback on a float
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: af, eric.smith, serhiy.storchaka
Priority: normal Keywords:

Created on 2019-08-16 14:22 by af, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg349866 - (view) Author: af (af) Date: 2019-08-16 14:22
json.loads traceback with:

[In [16]: json.loads("[1.e-8]")
---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
<ipython-input-16-bf0d3d6c51c5> in <module>()
----> 1 json.loads("[1.e-8]")

/scr/fonari/2019-4/internal/lib/python3.6/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    352             parse_int is None and parse_float is None and
    353             parse_constant is None and object_pairs_hook is None and not kw):
--> 354         return _default_decoder.decode(s)
    355     if cls is None:
    356         cls = JSONDecoder

/scr/fonari/2019-4/internal/lib/python3.6/json/decoder.py in decode(self, s, _w)
    337 
    338         """
--> 339         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    340         end = _w(s, end).end()
    341         if end != len(s):

/scr/fonari/2019-4/internal/lib/python3.6/json/decoder.py in raw_decode(self, s, idx)
    353         """
    354         try:
--> 355             obj, end = self.scan_once(s, idx)
    356         except StopIteration as err:
    357             raise JSONDecodeError("Expecting value", s, err.value) from None

JSONDecodeError: Expecting ',' delimiter: line 1 column 3 (char 2)

Works with json.loads("[1.0e-8]") and json.loads("[1e-8]")
msg349867 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-08-16 14:29
1.0e-8 is not a format for numbers in JSON. See RFC 7159 (https://tools.ietf.org/html/rfc7159.html#section-6):

      number = [ minus ] int [ frac ] [ exp ]

      decimal-point = %x2E       ; .

      digit1-9 = %x31-39         ; 1-9

      e = %x65 / %x45            ; e E

      exp = e [ minus / plus ] 1*DIGIT

      frac = decimal-point 1*DIGIT

      int = zero / ( digit1-9 *DIGIT )

      minus = %x2D               ; -

      plus = %x2B                ; +

      zero = %x30                ; 0
msg349871 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2019-08-16 15:11
I think Serhiy means 1.e-8 is not valid.

The spec says that at least one digit is required in the "frac" part, after the decimal.
msg349873 - (view) Author: af (af) Date: 2019-08-16 15:42
I understand, thanks.
History
Date User Action Args
2022-04-11 14:59:19adminsetgithub: 82055
2019-08-16 15:42:21afsetmessages: + msg349873
2019-08-16 15:11:41eric.smithsetnosy: + eric.smith
messages: + msg349871
2019-08-16 14:29:06serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg349867

resolution: not a bug
stage: resolved
2019-08-16 14:24:32afsettype: crash -> behavior
2019-08-16 14:22:41afcreate