diff options
author | Bob Ippolito <bob@redivi.com> | 2008-03-23 08:23:37 +0000 |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2008-03-23 08:23:37 +0000 |
commit | 5498fa8abac362faba41ac86bbccbfb284a246ec (patch) | |
tree | a9b8d698ec927ad84fef5be5c77d55ab72ec0e9a /simplejson/encoder.py | |
parent | f3d503d201501aa2fe7c0914ce6a3978023d6223 (diff) | |
download | simplejson-5498fa8abac362faba41ac86bbccbfb284a246ec.tar.gz |
more tests, python -msimplejson pretty printer
git-svn-id: http://simplejson.googlecode.com/svn/trunk@68 a4795897-2c25-0410-b006-0d3caba88fa1
Diffstat (limited to 'simplejson/encoder.py')
-rw-r--r-- | simplejson/encoder.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/simplejson/encoder.py b/simplejson/encoder.py index 7827deb..1c69b02 100644 --- a/simplejson/encoder.py +++ b/simplejson/encoder.py @@ -110,7 +110,7 @@ class JSONEncoder(object): key_separator = ': ' def __init__(self, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, - indent=None, separators=None, encoding='utf-8'): + indent=None, separators=None, encoding='utf-8', default=None): """ Constructor for JSONEncoder, with sensible defaults. @@ -145,6 +145,10 @@ class JSONEncoder(object): tuple. The default is (', ', ': '). To get the most compact JSON representation you should specify (',', ':') to eliminate whitespace. + If specified, default is a function that gets called for objects + that can't otherwise be serialized. It should return a JSON encodable + version of the object or raise a ``TypeError``. + If encoding is not None, then all input strings will be transformed into unicode using that encoding prior to JSON-encoding. The default is UTF-8. @@ -159,6 +163,8 @@ class JSONEncoder(object): self.current_indent_level = 0 if separators is not None: self.item_separator, self.key_separator = separators + if default is not None: + self.default = default self.encoding = encoding def _newline_indent(self): |