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

Function dump

Lib/json/__init__.py:120–182  ·  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``, ``int``, ``float``, ``bool``, ``None``) will be skipped instead of raising a ``TypeError``. If ``en

(obj, fp, *, 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

118)
119
120def dump(obj, fp, *, skipkeys=False, ensure_ascii=True, check_circular=True,
121 allow_nan=True, cls=None, indent=None, separators=None,
122 default=None, sort_keys=False, **kw):
123 """Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
124 ``.write()``-supporting file-like object).
125
126 If ``skipkeys`` is true then ``dict`` keys that are not basic types
127 (``str``, ``int``, ``float``, ``bool``, ``None``) will be skipped
128 instead of raising a ``TypeError``.
129
130 If ``ensure_ascii`` is false, then the strings written to ``fp`` can
131 contain non-ASCII and non-printable characters if they appear in strings
132 contained in ``obj``. Otherwise, all such characters are escaped in JSON
133 strings.
134
135 If ``check_circular`` is false, then the circular reference check
136 for container types will be skipped and a circular reference will
137 result in an ``RecursionError`` (or worse).
138
139 If ``allow_nan`` is false, then it will be a ``ValueError`` to
140 serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``)
141 in strict compliance of the JSON specification, instead of using the
142 JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
143
144 If ``indent`` is a non-negative integer, then JSON array elements and
145 object members will be pretty-printed with that indent level. An indent
146 level of 0 will only insert newlines. ``None`` is the most compact
147 representation.
148
149 If specified, ``separators`` should be an ``(item_separator,
150 key_separator)`` tuple. The default is ``(', ', ': ')`` if *indent* is
151 ``None`` and ``(',', ': ')`` otherwise. To get the most compact JSON
152 representation, you should specify ``(',', ':')`` to eliminate
153 whitespace.
154
155 ``default(obj)`` is a function that should return a serializable version
156 of obj or raise TypeError. The default simply raises TypeError.
157
158 If *sort_keys* is true (default: ``False``), then the output of
159 dictionaries will be sorted by key.
160
161 To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
162 ``.default()`` method to serialize additional types), specify it with
163 the ``cls`` kwarg; otherwise ``JSONEncoder`` is used.
164
165 """
166 # cached encoder
167 if (not skipkeys and ensure_ascii and
168 check_circular and allow_nan and
169 cls is None and indent is None and separators is None and
170 default is None and not sort_keys and not kw):
171 iterable = _default_encoder.iterencode(obj)
172 else:
173 if cls is None:
174 cls = JSONEncoder
175 iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
176 check_circular=check_circular, allow_nan=allow_nan, indent=indent,
177 separators=separators,

Callers

nothing calls this directly

Calls 3

iterencodeMethod · 0.80
clsClass · 0.50
writeMethod · 0.45

Tested by

no test coverage detected