
    i                     ,    S SK r SSKJr   " S S5      rg)    N   )DictExporterc                   4    \ rS rSrSrS	S jrS rS rS rSr	g)
JsonExporter   a  
Tree to JSON exporter.

The tree is converted to a dictionary via `dictexporter` and exported to JSON.

Keyword Arguments:
    dictexporter: Dictionary Exporter used (see :any:`DictExporter`).
    maxlevel (int): Limit export to this number of levels.
    kwargs: All other arguments are passed to
            :any:`json.dump`/:any:`json.dumps`.
            See documentation for reference.

>>> from anytree import AnyNode
>>> from anytree.exporter import JsonExporter
>>> root = AnyNode(a="root")
>>> s0 = AnyNode(a="sub0", parent=root)
>>> s0a = AnyNode(a="sub0A", b="foo", parent=s0)
>>> s0b = AnyNode(a="sub0B", parent=s0)
>>> s1 = AnyNode(a="sub1", parent=root)

>>> exporter = JsonExporter(indent=2, sort_keys=True)
>>> print(exporter.export(root))
{
  "a": "root",
  "children": [
    {
      "a": "sub0",
      "children": [
        {
          "a": "sub0A",
          "b": "foo"
        },
        {
          "a": "sub0B"
        }
      ]
    },
    {
      "a": "sub1"
    }
  ]
}

.. note:: Whenever the json output does not meet your expectations, see the :any:`json` documentation.
          For instance, if you have unicode/ascii issues, please try `JsonExporter(..., ensure_ascii=False)`.
Nc                 (    Xl         X l        X0l        g N)dictexportermaxlevelkwargs)selfr
   r   r   s       J/app/mltbenv/lib/python3.13/site-packages/anytree/exporter/jsonexporter.py__init__JsonExporter.__init__6   s    (     c                     U R                   =(       d
    [        5       nU R                  b  U R                  Ul        UR                  U5      $ r	   )r
   r   r   export)r   noder
   s      r   _exportJsonExporter._export;   s;    ((:LN==$$(MML!""4((r   c                 f    U R                  U5      n[        R                  " U40 U R                  D6$ )z(Return JSON for tree starting at `node`.)r   jsondumpsr   )r   r   datas      r   r   JsonExporter.exportA   s(    ||D!zz$.$++..r   c                 f    U R                  U5      n[        R                  " X240 U R                  D6$ )z.Write JSON to `filehandle` starting at `node`.)r   r   dumpr   )r   r   
filehandler   s       r   writeJsonExporter.writeF   s(    ||D!yy9T[[99r   )r
   r   r   )NN)
__name__
__module____qualname____firstlineno____doc__r   r   r   r   __static_attributes__ r   r   r   r      s    -^
)/
:r   r   )r   r
   r   r   r'   r   r   <module>r(      s     &C: C:r   