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

Method default

simplejson/encoder.py:271–290  ·  view source on GitHub ↗

Implement this method in a subclass such that it returns a serializable object for ``o``, or calls the base implementation (to raise a ``TypeError``). For example, to support arbitrary iterators, you could implement default like this:: def default(self,

(self, o)

Source from the content-addressed store, hash-verified

269 self.encoding = encoding
270
271 def default(self, o):
272 """Implement this method in a subclass such that it returns
273 a serializable object for ``o``, or calls the base implementation
274 (to raise a ``TypeError``).
275
276 For example, to support arbitrary iterators, you could
277 implement default like this::
278
279 def default(self, o):
280 try:
281 iterable = iter(o)
282 except TypeError:
283 pass
284 else:
285 return list(iterable)
286 return JSONEncoder.default(self, o)
287
288 """
289 raise TypeError('Object of type %s is not JSON serializable' %
290 o.__class__.__name__)
291
292 def encode(self, o):
293 """Return a JSON string representation of a Python data structure.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected