1

If we json_encode an array which has Inf or NaN then we get : Inf and NaN cannot be JSON encoded

The workaround as mentioned here - https://levels.io/inf-nan-json_encode/ is :

json_encode(unserialize(str_replace(array('NAN;','INF;'),'0;',serialize($reply))));

Is there any update on getting this resolved better using the latest PHP versions, say 8.0 or 8.1 ?

IMSoP
  • 89,526
  • 13
  • 117
  • 169
anjanesh
  • 3,771
  • 7
  • 44
  • 58
  • 1
    If a value of `0` is fine, you can use `JSON_PARTIAL_OUTPUT_ON_ERROR`. – 0stone0 May 31 '22 at 09:55
  • 1
    What would "resolved better" mean exactly? The limitation is not with PHP, it's with JSON. [RFC 8259](https://datatracker.ietf.org/doc/html/rfc8259#section-6) puts it this way "Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted." – IMSoP May 31 '22 at 15:21

0 Answers0