MCPcopy Index your code
hub / github.com/RustPython/RustPython / dumps

Function dumps

Lib/json/__init__.py:185–242  ·  view source on GitHub ↗

Serialize ``obj`` to a JSON formatted ``str``. If ``skipkeys`` is true then ``dict`` keys that are not basic types (``str``, ``int``, ``float``, ``bool``, ``None``) will be skipped instead of raising a ``TypeError``. If ``ensure_ascii`` is false, then the return value can contain

(obj, *, skipkeys=False, ensure_ascii=True, check_circular=True,
        allow_nan=True, cls=None, indent=None, separators=None,
        default=None, sort_keys=False, **kw)

Source from the content-addressed store, hash-verified

183
184
185def dumps(obj, *, skipkeys=False, ensure_ascii=True, check_circular=True,
186 allow_nan=True, cls=None, indent=None, separators=None,
187 default=None, sort_keys=False, **kw):
188 """Serialize ``obj`` to a JSON formatted ``str``.
189
190 If ``skipkeys`` is true then ``dict`` keys that are not basic types
191 (``str``, ``int``, ``float``, ``bool``, ``None``) will be skipped
192 instead of raising a ``TypeError``.
193
194 If ``ensure_ascii`` is false, then the return value can contain
195 non-ASCII and non-printable characters if they appear in strings
196 contained in ``obj``. Otherwise, all such characters are escaped in
197 JSON strings.
198
199 If ``check_circular`` is false, then the circular reference check
200 for container types will be skipped and a circular reference will
201 result in an ``RecursionError`` (or worse).
202
203 If ``allow_nan`` is false, then it will be a ``ValueError`` to
204 serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in
205 strict compliance of the JSON specification, instead of using the
206 JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
207
208 If ``indent`` is a non-negative integer, then JSON array elements and
209 object members will be pretty-printed with that indent level. An indent
210 level of 0 will only insert newlines. ``None`` is the most compact
211 representation.
212
213 If specified, ``separators`` should be an ``(item_separator,
214 key_separator)`` tuple. The default is ``(', ', ': ')`` if *indent* is
215 ``None`` and ``(',', ': ')`` otherwise. To get the most compact JSON
216 representation, you should specify ``(',', ':')`` to eliminate
217 whitespace.
218
219 ``default(obj)`` is a function that should return a serializable version
220 of obj or raise TypeError. The default simply raises TypeError.
221
222 If *sort_keys* is true (default: ``False``), then the output of
223 dictionaries will be sorted by key.
224
225 To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
226 ``.default()`` method to serialize additional types), specify it with
227 the ``cls`` kwarg; otherwise ``JSONEncoder`` is used.
228
229 """
230 # cached encoder
231 if (not skipkeys and ensure_ascii and
232 check_circular and allow_nan and
233 cls is None and indent is None and separators is None and
234 default is None and not sort_keys and not kw):
235 return _default_encoder.encode(obj)
236 if cls is None:
237 cls = JSONEncoder
238 return cls(
239 skipkeys=skipkeys, ensure_ascii=ensure_ascii,
240 check_circular=check_circular, allow_nan=allow_nan, indent=indent,
241 separators=separators, default=default, sort_keys=sort_keys,
242 **kw).encode(obj)

Callers 7

test_pickleMethod · 0.50
test_pickle_dump_loadFunction · 0.50
test_pickle_exceptionFunction · 0.50
test_pickleMethod · 0.50
custom_load_dumpMethod · 0.50

Calls 2

clsClass · 0.50
encodeMethod · 0.45

Tested by 7

test_pickleMethod · 0.40
test_pickle_dump_loadFunction · 0.40
test_pickle_exceptionFunction · 0.40
test_pickleMethod · 0.40
custom_load_dumpMethod · 0.40