[/
    Documentation for libzeep version 5.0

          Copyright Maarten L. Hekkelman, 2020
 Distributed under the Boost Software License, Version 1.0.
    (See accompanying file LICENSE_1_0.txt or copy at
          http://www.boost.org/LICENSE_1_0.txt)
]

[chapter JSON
    [quickbook 1.7]
    [id libzeep.json]
]

[section:descr Introduction]

The web application code for libzeep contained an implementation of [@https://en.wikipedia.org/wiki/Unified_Expression_Language expression language], a simple language used in the HTML templates. The variables in this language look and act a bit like objects in JavaScript. And then REST support was added and more support for [@https://www.json.org/ JSON] was needed.

For C++ there is already a very good JSON library available from [@https://github.com/nlohmann/json Niels Lohmann]. I tried to use this initially, but it didn't fit well into the rest of libzeep. Still I liked the way it worked and so I tried to create something that is source code compatible, however fancy stuff like JSON Pointer and JSON Patch are not available (yet).

This library just provides code to parse and write JSON. It stores the data in an efficient way, allows easy manipulation and also can use the same mechanism of serialization as the XML library.

[endsect:descr]

[section:elem The JSON element]

The main data structure in this library is __json_element__, this is the representation of a JSON object and thus can contain various types of data. See this synopsis on how to use it.

[import ../examples/synopsis-json.cpp]
[synopsis_json_main]

There is also support for `enum`s, see the following example. The idea is, you call the `std::value_serializer<Enum>::init` once to initialize the global mapping of enum values to strings. The name parameter is optional, but required if you use this serializer also in a SOAP controller.

[enum_support]
[enum_usage]

[heading STL-like interface]

The __json_element__ class acts as an STL container, see the class reference for more information. But to give you an idea:

[stl_interface]

[endsect:elem]