I found the following lines in the json/encoder.py
module:
if o != o:
text = 'NaN'
In what situation is an object not equal to itself?
This can happen in the case of floating point numbers that adhere to IEEE 754 standard. See Why is NaN not equal to NaN?
By definition, a value of NaN ("not a number") is unequal to itself.