{
    "content": [
        {
            "type": "text",
            "text": "# json (pydoc)\n\n**Summary:** json\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **MODULE REFERENCE** (8 lines)\n- **DESCRIPTION** (97 lines)\n- **PACKAGE CONTENTS** (5 lines)\n- **CLASSES** (6 lines) — 3 subsections\n  - class JSONDecodeError (78 lines)\n  - class JSONDecoder (85 lines)\n  - class JSONEncoder (120 lines)\n- **FUNCTIONS** (1 lines) — 4 subsections\n  - dump (40 lines)\n  - dumps (39 lines)\n  - load (17 lines)\n  - loads (32 lines)\n- **DATA** (2 lines)\n- **VERSION** (2 lines)\n- **AUTHOR** (2 lines)\n- **FILE** (3 lines)\n\n## Full Content\n\n### NAME\n\njson\n\n### MODULE REFERENCE\n\nhttps://docs.python.org/3.10/library/json.html\n\nThe following documentation is automatically generated from the Python\nsource files.  It may be incomplete, incorrect or include features that\nare considered implementation detail and may vary between Python\nimplementations.  When in doubt, consult the module reference at the\nlocation listed above.\n\n### DESCRIPTION\n\nJSON (JavaScript Object Notation) <https://json.org> is a subset of\nJavaScript syntax (ECMA-262 3rd edition) used as a lightweight data\ninterchange format.\n\n:mod:`json` exposes an API familiar to users of the standard library\n:mod:`marshal` and :mod:`pickle` modules.  It is derived from a\nversion of the externally maintained simplejson library.\n\nEncoding basic Python object hierarchies::\n\n>>> import json\n>>> json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])\n'[\"foo\", {\"bar\": [\"baz\", null, 1.0, 2]}]'\n>>> print(json.dumps(\"\\\"foo\\bar\"))\n\"\\\"foo\\bar\"\n>>> print(json.dumps('\\u1234'))\n\"\\u1234\"\n>>> print(json.dumps('\\\\'))\n\"\\\\\"\n>>> print(json.dumps({\"c\": 0, \"b\": 0, \"a\": 0}, sortkeys=True))\n{\"a\": 0, \"b\": 0, \"c\": 0}\n>>> from io import StringIO\n>>> io = StringIO()\n>>> json.dump(['streaming API'], io)\n>>> io.getvalue()\n'[\"streaming API\"]'\n\nCompact encoding::\n\n>>> import json\n>>> mydict = {'4': 5, '6': 7}\n>>> json.dumps([1,2,3,mydict], separators=(',', ':'))\n'[1,2,3,{\"4\":5,\"6\":7}]'\n\nPretty printing::\n\n>>> import json\n>>> print(json.dumps({'4': 5, '6': 7}, sortkeys=True, indent=4))\n{\n\"4\": 5,\n\"6\": 7\n}\n\nDecoding JSON::\n\n>>> import json\n>>> obj = ['foo', {'bar': ['baz', None, 1.0, 2]}]\n>>> json.loads('[\"foo\", {\"bar\":[\"baz\", null, 1.0, 2]}]') == obj\nTrue\n>>> json.loads('\"\\\\\"foo\\\\bar\"') == '\"foo\\x08ar'\nTrue\n>>> from io import StringIO\n>>> io = StringIO('[\"streaming API\"]')\n>>> json.load(io)[0] == 'streaming API'\nTrue\n\nSpecializing JSON object decoding::\n\n>>> import json\n>>> def ascomplex(dct):\n...     if 'complex' in dct:\n...         return complex(dct['real'], dct['imag'])\n...     return dct\n...\n>>> json.loads('{\"complex\": true, \"real\": 1, \"imag\": 2}',\n...     objecthook=ascomplex)\n(1+2j)\n>>> from decimal import Decimal\n>>> json.loads('1.1', parsefloat=Decimal) == Decimal('1.1')\nTrue\n\nSpecializing JSON object encoding::\n\n>>> import json\n>>> def encodecomplex(obj):\n...     if isinstance(obj, complex):\n...         return [obj.real, obj.imag]\n...     raise TypeError(f'Object of type {obj.class.name} '\n...                     f'is not JSON serializable')\n...\n>>> json.dumps(2 + 1j, default=encodecomplex)\n'[2.0, 1.0]'\n>>> json.JSONEncoder(default=encodecomplex).encode(2 + 1j)\n'[2.0, 1.0]'\n>>> ''.join(json.JSONEncoder(default=encodecomplex).iterencode(2 + 1j))\n'[2.0, 1.0]'\n\n\nUsing json.tool from the shell to validate and pretty-print::\n\n$ echo '{\"json\":\"obj\"}' | python -m json.tool\n{\n\"json\": \"obj\"\n}\n$ echo '{ 1.2:3.4}' | python -m json.tool\nExpecting property name enclosed in double quotes: line 1 column 3 (char 2)\n\n### PACKAGE CONTENTS\n\ndecoder\nencoder\nscanner\ntool\n\n### CLASSES\n\nbuiltins.ValueError(builtins.Exception)\njson.decoder.JSONDecodeError\nbuiltins.object\njson.decoder.JSONDecoder\njson.encoder.JSONEncoder\n\n#### class JSONDecodeError\n\n|  JSONDecodeError(msg, doc, pos)\n|\n|  Subclass of ValueError with the following additional properties:\n|\n|  msg: The unformatted error message\n|  doc: The JSON document being parsed\n|  pos: The start index of doc where parsing failed\n|  lineno: The line corresponding to pos\n|  colno: The column corresponding to pos\n|\n|  Method resolution order:\n|      JSONDecodeError\n|      builtins.ValueError\n|      builtins.Exception\n|      builtins.BaseException\n|      builtins.object\n|\n|  Methods defined here:\n|\n|  init(self, msg, doc, pos)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  reduce(self)\n|      Helper for pickle.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Static methods inherited from builtins.ValueError:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.BaseException:\n|\n|  delattr(self, name, /)\n|      Implement delattr(self, name).\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  setattr(self, name, value, /)\n|      Implement setattr(self, name, value).\n|\n|  setstate(...)\n|\n|  str(self, /)\n|      Return str(self).\n|\n|  withtraceback(...)\n|      Exception.withtraceback(tb) --\n|      set self.traceback to tb and return self.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from builtins.BaseException:\n|\n|  cause\n|      exception cause\n|\n|  context\n|      exception context\n|\n|  dict\n|\n|  suppresscontext\n|\n|  traceback\n|\n|  args\n\n#### class JSONDecoder\n\n|  JSONDecoder(*, objecthook=None, parsefloat=None, parseint=None, parseconstant=None, strict=True, objectpairshook=None)\n|\n|  Simple JSON <https://json.org> decoder\n|\n|  Performs the following translations in decoding by default:\n|\n|  +---------------+-------------------+\n|  | JSON          | Python            |\n|  +===============+===================+\n|  | object        | dict              |\n|  +---------------+-------------------+\n|  | array         | list              |\n|  +---------------+-------------------+\n|  | string        | str               |\n|  +---------------+-------------------+\n|  | number (int)  | int               |\n|  +---------------+-------------------+\n|  | number (real) | float             |\n|  +---------------+-------------------+\n|  | true          | True              |\n|  +---------------+-------------------+\n|  | false         | False             |\n|  +---------------+-------------------+\n|  | null          | None              |\n|  +---------------+-------------------+\n|\n|  It also understands ``NaN``, ``Infinity``, and ``-Infinity`` as\n|  their corresponding ``float`` values, which is outside the JSON spec.\n|\n|  Methods defined here:\n|\n|  init(self, *, objecthook=None, parsefloat=None, parseint=None, parseconstant=None, strict=True, objectpairshook=None)\n|      ``objecthook``, if specified, will be called with the result\n|      of every JSON object decoded and its return value will be used in\n|      place of the given ``dict``.  This can be used to provide custom\n|      deserializations (e.g. to support JSON-RPC class hinting).\n|\n|      ``objectpairshook``, if specified will be called with the result of\n|      every JSON object decoded with an ordered list of pairs.  The return\n|      value of ``objectpairshook`` will be used instead of the ``dict``.\n|      This feature can be used to implement custom decoders.\n|      If ``objecthook`` is also defined, the ``objectpairshook`` takes\n|      priority.\n|\n|      ``parsefloat``, if specified, will be called with the string\n|      of every JSON float to be decoded. By default this is equivalent to\n|      float(numstr). This can be used to use another datatype or parser\n|      for JSON floats (e.g. decimal.Decimal).\n|\n|      ``parseint``, if specified, will be called with the string\n|      of every JSON int to be decoded. By default this is equivalent to\n|      int(numstr). This can be used to use another datatype or parser\n|      for JSON integers (e.g. float).\n|\n|      ``parseconstant``, if specified, will be called with one of the\n|      following strings: -Infinity, Infinity, NaN.\n|      This can be used to raise an exception if invalid JSON numbers\n|      are encountered.\n|\n|      If ``strict`` is false (true is the default), then control\n|      characters will be allowed inside strings.  Control characters in\n|      this context are those with character codes in the 0-31 range,\n|      including ``'\\t'`` (tab), ``'\\n'``, ``'\\r'`` and ``'\\0'``.\n|\n|  decode(self, s, w=<built-in method match of re.Pattern object at 0x7fd8491cedc0>)\n|      Return the Python representation of ``s`` (a ``str`` instance\n|      containing a JSON document).\n|\n|  rawdecode(self, s, idx=0)\n|      Decode a JSON document from ``s`` (a ``str`` beginning with\n|      a JSON document) and return a 2-tuple of the Python\n|      representation and the index in ``s`` where the document ended.\n|\n|      This can be used to decode a JSON document from a string that may\n|      have extraneous data at the end.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  dict\n|      dictionary for instance variables (if defined)\n|\n|  weakref\n|      list of weak references to the object (if defined)\n\n#### class JSONEncoder\n\n|  JSONEncoder(*, skipkeys=False, ensureascii=True, checkcircular=True, allownan=True, sortkeys=False, indent=None, separators=None, default=None)\n|\n|  Extensible JSON <https://json.org> encoder for Python data structures.\n|\n|  Supports the following objects and types by default:\n|\n|  +-------------------+---------------+\n|  | Python            | JSON          |\n|  +===================+===============+\n|  | dict              | object        |\n|  +-------------------+---------------+\n|  | list, tuple       | array         |\n|  +-------------------+---------------+\n|  | str               | string        |\n|  +-------------------+---------------+\n|  | int, float        | number        |\n|  +-------------------+---------------+\n|  | True              | true          |\n|  +-------------------+---------------+\n|  | False             | false         |\n|  +-------------------+---------------+\n|  | None              | null          |\n|  +-------------------+---------------+\n|\n|  To extend this to recognize other objects, subclass and implement a\n|  ``.default()`` method with another method that returns a serializable\n|  object for ``o`` if possible, otherwise it should call the superclass\n|  implementation (to raise ``TypeError``).\n|\n|  Methods defined here:\n|\n|  init(self, *, skipkeys=False, ensureascii=True, checkcircular=True, allownan=True, sortkeys=False, indent=None, separators=None, default=None)\n|      Constructor for JSONEncoder, with sensible defaults.\n|\n|      If skipkeys is false, then it is a TypeError to attempt\n|      encoding of keys that are not str, int, float or None.  If\n|      skipkeys is True, such items are simply skipped.\n|\n|      If ensureascii is true, the output is guaranteed to be str\n|      objects with all incoming non-ASCII characters escaped.  If\n|      ensureascii is false, the output can contain non-ASCII characters.\n|\n|      If checkcircular is true, then lists, dicts, and custom encoded\n|      objects will be checked for circular references during encoding to\n|      prevent an infinite recursion (which would cause an RecursionError).\n|      Otherwise, no such check takes place.\n|\n|      If allownan is true, then NaN, Infinity, and -Infinity will be\n|      encoded as such.  This behavior is not JSON specification compliant,\n|      but is consistent with most JavaScript based encoders and decoders.\n|      Otherwise, it will be a ValueError to encode such floats.\n|\n|      If sortkeys is true, then the output of dictionaries will be\n|      sorted by key; this is useful for regression tests to ensure\n|      that JSON serializations can be compared on a day-to-day basis.\n|\n|      If indent is a non-negative integer, then JSON array\n|      elements and object members will be pretty-printed with that\n|      indent level.  An indent level of 0 will only insert newlines.\n|      None is the most compact representation.\n|\n|      If specified, separators should be an (itemseparator, keyseparator)\n|      tuple.  The default is (', ', ': ') if *indent* is ``None`` and\n|      (',', ': ') otherwise.  To get the most compact JSON representation,\n|      you should specify (',', ':') to eliminate whitespace.\n|\n|      If specified, default is a function that gets called for objects\n|      that can't otherwise be serialized.  It should return a JSON encodable\n|      version of the object or raise a ``TypeError``.\n|\n|  default(self, o)\n|      Implement this method in a subclass such that it returns\n|      a serializable object for ``o``, or calls the base implementation\n|      (to raise a ``TypeError``).\n|\n|      For example, to support arbitrary iterators, you could\n|      implement default like this::\n|\n|          def default(self, o):\n|              try:\n|                  iterable = iter(o)\n|              except TypeError:\n|                  pass\n|              else:\n|                  return list(iterable)\n|              # Let the base class default method raise the TypeError\n|              return JSONEncoder.default(self, o)\n|\n|  encode(self, o)\n|      Return a JSON string representation of a Python data structure.\n|\n|      >>> from json.encoder import JSONEncoder\n|      >>> JSONEncoder().encode({\"foo\": [\"bar\", \"baz\"]})\n|      '{\"foo\": [\"bar\", \"baz\"]}'\n|\n|  iterencode(self, o, oneshot=False)\n|      Encode the given object and yield each string\n|      representation as available.\n|\n|      For example::\n|\n|          for chunk in JSONEncoder().iterencode(bigobject):\n|              mysocket.write(chunk)\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  dict\n|      dictionary for instance variables (if defined)\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Data and other attributes defined here:\n|\n|  itemseparator = ', '\n|\n|  keyseparator = ': '\n\n### FUNCTIONS\n\n#### dump\n\nSerialize ``obj`` as a JSON formatted stream to ``fp`` (a\n``.write()``-supporting file-like object).\n\nIf ``skipkeys`` is true then ``dict`` keys that are not basic types\n(``str``, ``int``, ``float``, ``bool``, ``None``) will be skipped\ninstead of raising a ``TypeError``.\n\nIf ``ensureascii`` is false, then the strings written to ``fp`` can\ncontain non-ASCII characters if they appear in strings contained in\n``obj``. Otherwise, all such characters are escaped in JSON strings.\n\nIf ``checkcircular`` is false, then the circular reference check\nfor container types will be skipped and a circular reference will\nresult in an ``RecursionError`` (or worse).\n\nIf ``allownan`` is false, then it will be a ``ValueError`` to\nserialize out of range ``float`` values (``nan``, ``inf``, ``-inf``)\nin strict compliance of the JSON specification, instead of using the\nJavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).\n\nIf ``indent`` is a non-negative integer, then JSON array elements and\nobject members will be pretty-printed with that indent level. An indent\nlevel of 0 will only insert newlines. ``None`` is the most compact\nrepresentation.\n\nIf specified, ``separators`` should be an ``(itemseparator, keyseparator)``\ntuple.  The default is ``(', ', ': ')`` if *indent* is ``None`` and\n``(',', ': ')`` otherwise.  To get the most compact JSON representation,\nyou should specify ``(',', ':')`` to eliminate whitespace.\n\n``default(obj)`` is a function that should return a serializable version\nof obj or raise TypeError. The default simply raises TypeError.\n\nIf *sortkeys* is true (default: ``False``), then the output of\ndictionaries will be sorted by key.\n\nTo use a custom ``JSONEncoder`` subclass (e.g. one that overrides the\n``.default()`` method to serialize additional types), specify it with\nthe ``cls`` kwarg; otherwise ``JSONEncoder`` is used.\n\n#### dumps\n\nSerialize ``obj`` to a JSON formatted ``str``.\n\nIf ``skipkeys`` is true then ``dict`` keys that are not basic types\n(``str``, ``int``, ``float``, ``bool``, ``None``) will be skipped\ninstead of raising a ``TypeError``.\n\nIf ``ensureascii`` is false, then the return value can contain non-ASCII\ncharacters if they appear in strings contained in ``obj``. Otherwise, all\nsuch characters are escaped in JSON strings.\n\nIf ``checkcircular`` is false, then the circular reference check\nfor container types will be skipped and a circular reference will\nresult in an ``RecursionError`` (or worse).\n\nIf ``allownan`` is false, then it will be a ``ValueError`` to\nserialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in\nstrict compliance of the JSON specification, instead of using the\nJavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).\n\nIf ``indent`` is a non-negative integer, then JSON array elements and\nobject members will be pretty-printed with that indent level. An indent\nlevel of 0 will only insert newlines. ``None`` is the most compact\nrepresentation.\n\nIf specified, ``separators`` should be an ``(itemseparator, keyseparator)``\ntuple.  The default is ``(', ', ': ')`` if *indent* is ``None`` and\n``(',', ': ')`` otherwise.  To get the most compact JSON representation,\nyou should specify ``(',', ':')`` to eliminate whitespace.\n\n``default(obj)`` is a function that should return a serializable version\nof obj or raise TypeError. The default simply raises TypeError.\n\nIf *sortkeys* is true (default: ``False``), then the output of\ndictionaries will be sorted by key.\n\nTo use a custom ``JSONEncoder`` subclass (e.g. one that overrides the\n``.default()`` method to serialize additional types), specify it with\nthe ``cls`` kwarg; otherwise ``JSONEncoder`` is used.\n\n#### load\n\nDeserialize ``fp`` (a ``.read()``-supporting file-like object containing\na JSON document) to a Python object.\n\n``objecthook`` is an optional function that will be called with the\nresult of any object literal decode (a ``dict``). The return value of\n``objecthook`` will be used instead of the ``dict``. This feature\ncan be used to implement custom decoders (e.g. JSON-RPC class hinting).\n\n``objectpairshook`` is an optional function that will be called with the\nresult of any object literal decoded with an ordered list of pairs.  The\nreturn value of ``objectpairshook`` will be used instead of the ``dict``.\nThis feature can be used to implement custom decoders.  If ``objecthook``\nis also defined, the ``objectpairshook`` takes priority.\n\nTo use a custom ``JSONDecoder`` subclass, specify it with the ``cls``\nkwarg; otherwise ``JSONDecoder`` is used.\n\n#### loads\n\nDeserialize ``s`` (a ``str``, ``bytes`` or ``bytearray`` instance\ncontaining a JSON document) to a Python object.\n\n``objecthook`` is an optional function that will be called with the\nresult of any object literal decode (a ``dict``). The return value of\n``objecthook`` will be used instead of the ``dict``. This feature\ncan be used to implement custom decoders (e.g. JSON-RPC class hinting).\n\n``objectpairshook`` is an optional function that will be called with the\nresult of any object literal decoded with an ordered list of pairs.  The\nreturn value of ``objectpairshook`` will be used instead of the ``dict``.\nThis feature can be used to implement custom decoders.  If ``objecthook``\nis also defined, the ``objectpairshook`` takes priority.\n\n``parsefloat``, if specified, will be called with the string\nof every JSON float to be decoded. By default this is equivalent to\nfloat(numstr). This can be used to use another datatype or parser\nfor JSON floats (e.g. decimal.Decimal).\n\n``parseint``, if specified, will be called with the string\nof every JSON int to be decoded. By default this is equivalent to\nint(numstr). This can be used to use another datatype or parser\nfor JSON integers (e.g. float).\n\n``parseconstant``, if specified, will be called with one of the\nfollowing strings: -Infinity, Infinity, NaN.\nThis can be used to raise an exception if invalid JSON numbers\nare encountered.\n\nTo use a custom ``JSONDecoder`` subclass, specify it with the ``cls``\nkwarg; otherwise ``JSONDecoder`` is used.\n\n### DATA\n\nall = ['dump', 'dumps', 'load', 'loads', 'JSONDecoder', 'JSONDecod...\n\n### VERSION\n\n2.0.9\n\n### AUTHOR\n\nBob Ippolito <bob@redivi.com>\n\n### FILE\n\n/usr/lib/python3.10/json/init.py\n\n"
        }
    ],
    "structuredContent": {
        "command": "json",
        "section": "",
        "mode": "pydoc",
        "summary": "json",
        "synopsis": null,
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "MODULE REFERENCE",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 97,
                "subsections": []
            },
            {
                "name": "PACKAGE CONTENTS",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "CLASSES",
                "lines": 6,
                "subsections": [
                    {
                        "name": "class JSONDecodeError",
                        "lines": 78
                    },
                    {
                        "name": "class JSONDecoder",
                        "lines": 85
                    },
                    {
                        "name": "class JSONEncoder",
                        "lines": 120
                    }
                ]
            },
            {
                "name": "FUNCTIONS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "dump",
                        "lines": 40
                    },
                    {
                        "name": "dumps",
                        "lines": 39
                    },
                    {
                        "name": "load",
                        "lines": 17
                    },
                    {
                        "name": "loads",
                        "lines": 32
                    }
                ]
            },
            {
                "name": "DATA",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "FILE",
                "lines": 3,
                "subsections": []
            }
        ]
    }
}