MCPcopy Index your code
hub / github.com/clips/pattern / dump

Function dump

pattern/web/json/__init__.py:145–242  ·  view source on GitHub ↗

Serialize ``obj`` as a JSON formatted stream to ``fp`` (a ``.write()``-supporting file-like object). If ``skipkeys`` is true then ``dict`` keys that are not basic types (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``) will be skipped instead of raising a ``Ty

(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
        allow_nan=True, cls=None, indent=None, separators=None,
        encoding='utf-8', default=None, use_decimal=True,
        namedtuple_as_object=True, tuple_as_array=True,
        bigint_as_string=False, sort_keys=False, item_sort_key=None,
        **kw)

Source from the content-addressed store, hash-verified

143)
144
145def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
146 allow_nan=True, cls=None, indent=None, separators=None,
147 encoding='utf-8', default=None, use_decimal=True,
148 namedtuple_as_object=True, tuple_as_array=True,
149 bigint_as_string=False, sort_keys=False, item_sort_key=None,
150 **kw):
151 """Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
152 ``.write()``-supporting file-like object).
153
154 If ``skipkeys`` is true then ``dict`` keys that are not basic types
155 (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
156 will be skipped instead of raising a ``TypeError``.
157
158 If ``ensure_ascii`` is false, then the some chunks written to ``fp``
159 may be ``unicode`` instances, subject to normal Python ``str`` to
160 ``unicode`` coercion rules. Unless ``fp.write()`` explicitly
161 understands ``unicode`` (as in ``codecs.getwriter()``) this is likely
162 to cause an error.
163
164 If ``check_circular`` is false, then the circular reference check
165 for container types will be skipped and a circular reference will
166 result in an ``OverflowError`` (or worse).
167
168 If ``allow_nan`` is false, then it will be a ``ValueError`` to
169 serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``)
170 in strict compliance of the JSON specification, instead of using the
171 JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
172
173 If *indent* is a string, then JSON array elements and object members
174 will be pretty-printed with a newline followed by that string repeated
175 for each level of nesting. ``None`` (the default) selects the most compact
176 representation without any newlines. For backwards compatibility with
177 versions of simplejson earlier than 2.1.0, an integer is also accepted
178 and is converted to a string with that many spaces.
179
180 If ``separators`` is an ``(item_separator, dict_separator)`` tuple
181 then it will be used instead of the default ``(', ', ': ')`` separators.
182 ``(',', ':')`` is the most compact JSON representation.
183
184 ``encoding`` is the character encoding for str instances, default is UTF-8.
185
186 ``default(obj)`` is a function that should return a serializable version
187 of obj or raise TypeError. The default simply raises TypeError.
188
189 If *use_decimal* is true (default: ``True``) then decimal.Decimal
190 will be natively serialized to JSON with full precision.
191
192 If *namedtuple_as_object* is true (default: ``True``),
193 :class:`tuple` subclasses with ``_asdict()`` methods will be encoded
194 as JSON objects.
195
196 If *tuple_as_array* is true (default: ``True``),
197 :class:`tuple` (and subclasses) will be encoded as JSON arrays.
198
199 If *bigint_as_string* is true (default: ``False``), ints 2**53 and higher
200 or lower than -2**53 will be encoded as strings. This is to avoid the
201 rounding that happens in Javascript otherwise. Note that this is still a
202 lossy operation that will not round-trip correctly and should be used

Callers

nothing calls this directly

Calls 2

writeMethod · 0.80
iterencodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…