makamaka / JSON

perl implementation of JSON encoder/decoder
42 stars 40 forks source link

How to handle inf/nan #21

Open rurban opened 9 years ago

rurban commented 9 years ago

I got this ticket: https://github.com/rurban/Cpanel-JSON-XS/issues/28 "inf and nan encoded as invalid JSON"

I know that inf and nan are not encodable in JSON, but inf or nan are invalid JavaScript. perl -MJSON -e'print encode_json([9**9**9])' => [inf]

Other JSON libraries encode it as null, and Mojo::JSON stepped forward by stringifying it. I have no opinion, but either one of those solution would be better than the invalid inf or nan, we currently have.

charsbar commented 7 years ago

Hi. My (and I suppose makamaka's) apologies for a too-late reply.

I asked Marc about this, and as you have been informed previously (https://github.com/rurban/Cpanel-JSON-XS/issues/28#issuecomment-65086067), I was patiently told that this issue was too controversial, and it'd be better to keep the current behavior, considering the cost of migration, performance and maintenance (especially for JSON::XS).

I know you have already implemented your fix for this issue differently, and I'm not going to ask you to change that for now, but I'd like to let you know that both makamaka and I decided to folllow Marc's decision because both (three, actually) of us don't like the idea to convert inf/nan into null by default. I'm going to add some explanation to the JSON::PP's doc.

Your thoughts?