{"action":"created","issue":{"url":"https://api.github.com/repos/micropython/micropython/issues/3511","repository_url":"https://api.github.com/repos/micropython/micropython","labels_url":"https://api.github.com/repos/micropython/micropython/issues/3511/labels{/name}","comments_url":"https://api.github.com/repos/micropython/micropython/issues/3511/comments","events_url":"https://api.github.com/repos/micropython/micropython/issues/3511/events","html_url":"https://github.com/micropython/micropython/issues/3511","id":283950090,"node_id":"MDU6SXNzdWUyODM5NTAwOTA=","number":3511,"title":"ujson dumps NaN but doesn't load it","user":{"login":"stinos","id":1902997,"node_id":"MDQ6VXNlcjE5MDI5OTc=","avatar_url":"https://avatars3.githubusercontent.com/u/1902997?v=4","gravatar_id":"","url":"https://api.github.com/users/stinos","html_url":"https://github.com/stinos","followers_url":"https://api.github.com/users/stinos/followers","following_url":"https://api.github.com/users/stinos/following{/other_user}","gists_url":"https://api.github.com/users/stinos/gists{/gist_id}","starred_url":"https://api.github.com/users/stinos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stinos/subscriptions","organizations_url":"https://api.github.com/users/stinos/orgs","repos_url":"https://api.github.com/users/stinos/repos","events_url":"https://api.github.com/users/stinos/events{/privacy}","received_events_url":"https://api.github.com/users/stinos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-12-21T17:20:39Z","updated_at":"2018-09-27T13:09:29Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"The mod_ujson_load function doesn't handle `nan` though it is a valid representation:\r\n```\r\n>>> import ujson\r\n>>> ujson.dumps(float('nan'))\r\n'nan'\r\n>>> ujson.loads(ujson.dumps(float('nan')))\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\nValueError: syntax error in JSON\r\n```\r\nQuick hack to solve this (sorry couldn't immediately figure out how to get the nan constant), line 115 in modujson.c:\r\n```\r\n                } else if (S_CUR(s) == 'a' && S_NEXT(s) == 'n') {\r\n                    S_NEXT(s);\r\n                    next = mp_parse_num_decimal(\"nan\", 3, false, false, NULL);\r\n```"},"comment":{"url":"https://api.github.com/repos/micropython/micropython/issues/comments/425084250","html_url":"https://github.com/micropython/micropython/issues/3511#issuecomment-425084250","issue_url":"https://api.github.com/repos/micropython/micropython/issues/3511","id":425084250,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNTA4NDI1MA==","user":{"login":"martijnthe","id":193881,"node_id":"MDQ6VXNlcjE5Mzg4MQ==","avatar_url":"https://avatars3.githubusercontent.com/u/193881?v=4","gravatar_id":"","url":"https://api.github.com/users/martijnthe","html_url":"https://github.com/martijnthe","followers_url":"https://api.github.com/users/martijnthe/followers","following_url":"https://api.github.com/users/martijnthe/following{/other_user}","gists_url":"https://api.github.com/users/martijnthe/gists{/gist_id}","starred_url":"https://api.github.com/users/martijnthe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martijnthe/subscriptions","organizations_url":"https://api.github.com/users/martijnthe/orgs","repos_url":"https://api.github.com/users/martijnthe/repos","events_url":"https://api.github.com/users/martijnthe/events{/privacy}","received_events_url":"https://api.github.com/users/martijnthe/received_events","type":"User","site_admin":false},"created_at":"2018-09-27T13:09:29Z","updated_at":"2018-09-27T13:09:29Z","author_association":"NONE","body":"> At least now you know it when something goes wrong..\r\n\r\nHow about raising a `ValueError` when a `nan`, `inf` or `-inf` (or any other value that can't be JSON-serialized) is passed? (So basically what would happen in Python if you'd add `allow_nan=False`.)\r\n\r\nDeviating from standard specs in ways that breaks the format is a no-no, IMO... I'm actually really (unpleasantly) surprised Python defaults to `allow_nan=True` and spits out non-spec-compliant \"JSON\"."}}
{"actor":{"display_login":"martijnthe"}}