simplejson/simplejson — Issue #19: Default direttive ignored
Author: rriggio
Created: 2011-10-21 13:30:39+00:00
State: open

I would like to override the serialization of NaN fields. Consider for example this piece of code:

import simplejson

def encode_nan(obj):
if isinstance(obj, NaN):
return 0
raise TypeError(repr(obj) + " is not JSON serializable")

print simplejson.dumps(float('nan'), default=encode_nan)

The output in this case is

NaN

instead as far as I've unserstood from the documentation the output should be

0

Using simplejson 2.2.1