
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/standalone/json_parser_main.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_examples_standalone_json_parser_main.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_standalone_json_parser_main.py:


Standalone Parser
===================================

    This example demonstrates how to generate and use the standalone parser,
    using the JSON example.

    See README.md for more details.

.. GENERATED FROM PYTHON SOURCE LINES 10-37

.. code-block:: default


    import sys

    from json_parser import Lark_StandAlone, Transformer, v_args

    inline_args = v_args(inline=True)

    class TreeToJson(Transformer):
        @inline_args
        def string(self, s):
            return s[1:-1].replace('\\"', '"')

        array = list
        pair = tuple
        object = dict
        number = inline_args(float)

        null = lambda self, _: None
        true = lambda self, _: True
        false = lambda self, _: False


    parser = Lark_StandAlone(transformer=TreeToJson())

    if __name__ == '__main__':
        with open(sys.argv[1]) as f:
            print(parser.parse(f.read()))


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  0.000 seconds)


.. _sphx_glr_download_examples_standalone_json_parser_main.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download sphx-glr-download-python

     :download:`Download Python source code: json_parser_main.py <json_parser_main.py>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: json_parser_main.ipynb <json_parser_main.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
