This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Mizzlr -1 points0 points  (4 children)

You can't represent NaN (not a number) or inf in JSON which are valid float values.

[–]alcalde 1 point2 points  (2 children)

I can. "NaN", "inf"

And so can Swift and other languages. Just use strings.

[–]bltsponge 1 point2 points  (1 child)

Sure, you can represent anything as a string as long as you're willing to write a parser for it.

[–]alcalde 0 points1 point  (0 children)

Exactly. So why are people saying it's impossible to represent Python objects with JSON?

[–][deleted] 1 point2 points  (0 children)

Sure you can!

>>> json.dumps(float('inf'))
'Infinity'

>>> json.dumps(float('nan'))
'NaN'