Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"inf" creates invalid JSON #27

Closed
nhthn opened this issue Jan 13, 2017 · 2 comments
Closed

"inf" creates invalid JSON #27

nhthn opened this issue Jan 13, 2017 · 2 comments

Comments

@nhthn
Copy link

nhthn commented Jan 13, 2017

sclang.interpret("inf");
-> Uncaught SyntaxError: Unexpected token I in JSON at position 0
@crucialfelix
Copy link
Owner

I guess there is no legal way to represent those in JSON. They are valid JavaScript, but not valid JSON.

http://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript

It is because they are properties of window, not primitive types. window.Infinity - anybody could redefine that.

JSON.parse('{"num": Infinity}')
VM1027:1 Uncaught SyntaxError: Unexpected token I in JSON at position 8
    at JSON.parse (<anonymous>)
    at <anonymous>:1:6
(anonymous) @ VM1026:1

// maybe just use a string for now
JSON.parse('{"num": "Infinity"}')
Object {num: "Infinity"}

I could convert the JSON.parse result to real Infinity objects

@nhthn
Copy link
Author

nhthn commented Jan 17, 2017

My workaround for now is to preprocess the object by replacing infinities with the strings "Infinity" and "-Infinity", and in JS I can postprocess numeric values using the unary + operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants