MCPcopy Create free account
hub / github.com/simplejson/simplejson / __init__

Method __init__

simplejson/encoder.py:157–269  ·  view source on GitHub ↗

Constructor for JSONEncoder, with sensible defaults. If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, long, float or None. If skipkeys is True, such items are simply skipped. If ensure_ascii is true, the output is guar

(self, skipkeys=False, ensure_ascii=True,
                 check_circular=True, allow_nan=False, sort_keys=False,
                 indent=None, separators=None, encoding='utf-8', default=None,
                 use_decimal=True, namedtuple_as_object=True,
                 tuple_as_array=True, bigint_as_string=False,
                 item_sort_key=None, for_json=False, ignore_nan=False,
                 int_as_string_bitcount=None, iterable_as_array=False)

Source from the content-addressed store, hash-verified

155 key_separator = ': '
156
157 def __init__(self, skipkeys=False, ensure_ascii=True,
158 check_circular=True, allow_nan=False, sort_keys=False,
159 indent=None, separators=None, encoding='utf-8', default=None,
160 use_decimal=True, namedtuple_as_object=True,
161 tuple_as_array=True, bigint_as_string=False,
162 item_sort_key=None, for_json=False, ignore_nan=False,
163 int_as_string_bitcount=None, iterable_as_array=False):
164 """Constructor for JSONEncoder, with sensible defaults.
165
166 If skipkeys is false, then it is a TypeError to attempt
167 encoding of keys that are not str, int, long, float or None. If
168 skipkeys is True, such items are simply skipped.
169
170 If ensure_ascii is true, the output is guaranteed to be str
171 objects with all incoming unicode characters escaped. If
172 ensure_ascii is false, the output will be unicode object.
173
174 If check_circular is true, then lists, dicts, and custom encoded
175 objects will be checked for circular references during encoding to
176 prevent an infinite recursion (which would cause an OverflowError).
177 Otherwise, no such check takes place.
178
179 If allow_nan is true (default: False), then out of range float
180 values (nan, inf, -inf) will be serialized to
181 their JavaScript equivalents (NaN, Infinity, -Infinity)
182 instead of raising a ValueError. See
183 ignore_nan for ECMA-262 compliant behavior.
184
185 If sort_keys is true, then the output of dictionaries will be
186 sorted by key; this is useful for regression tests to ensure
187 that JSON serializations can be compared on a day-to-day basis.
188
189 If indent is a string, then JSON array elements and object members
190 will be pretty-printed with a newline followed by that string repeated
191 for each level of nesting. ``None`` (the default) selects the most compact
192 representation without any newlines. For backwards compatibility with
193 versions of simplejson earlier than 2.1.0, an integer is also accepted
194 and is converted to a string with that many spaces.
195
196 If specified, separators should be an (item_separator, key_separator)
197 tuple. The default is (', ', ': ') if *indent* is ``None`` and
198 (',', ': ') otherwise. To get the most compact JSON representation,
199 you should specify (',', ':') to eliminate whitespace.
200
201 If specified, default is a function that gets called for objects
202 that can't otherwise be serialized. It should return a JSON encodable
203 version of the object or raise a ``TypeError``.
204
205 If encoding is not None, then all input strings will be
206 transformed into unicode using that encoding prior to JSON-encoding.
207 The default is UTF-8.
208
209 If use_decimal is true (default: ``True``), ``decimal.Decimal`` will
210 be supported directly by the encoder. For the inverse, decode JSON
211 with ``parse_float=decimal.Decimal``.
212
213 If namedtuple_as_object is true (the default), objects with
214 ``_asdict()`` methods will be encoded as JSON objects.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected