ID EN
JSON

JSONEncoder

Python 3.11 🇮🇩 Bahasa Indonesia

Encoder JSON yang dapat diperluas untuk struktur data Python.

Syntax

PYTHON
class json.JSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Contoh

Example 1
PYTHON
def default(self, o):
   try:
       iterable = iter(o)
   except TypeError:
       pass
   else:
       return list(iterable)
    Let the base class default method raise the TypeError
   return super().default(o)
Example 2
PYTHON
>>> json.JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
Example 3
PYTHON
for chunk in json.JSONEncoder().iterencode(bigobject):
    mysocket.write(chunk)

See Also

default() TypeError TypeError str int float RecursionError ValueError