# Using the low-level parser

The following code snippet shows how to use the low-level `json_parser` class by providing an own handler class and passing it as a template argument:

    #include <orcus/json_parser.hpp>
    #include <cstring>
    #include <iostream>

    class json_parser_handler : public orcus::json_handler
    {
    public:
        void object_key(std::string_view key, bool /*transient*/)
        {
            std::cout << "object key: " << key << std::endl;
        }

        void string(std::string_view val, bool /*transient*/)
        {
            std::cout << "string: " << val << std::endl;
        }

        void number(double val)
        {
            std::cout << "number: " << val << std::endl;
        }
    };

    int main()
    {
        const char* test_code = "{\"key1\": [1,2,3,4,5], \"key2\": 12.3}";

        std::cout << "JSON string: " << test_code << std::endl;

        // Instantiate the parser with an own handler.
        json_parser_handler hdl;
        orcus::json_parser<json_parser_handler> parser(test_code, hdl);

        // Parse the string.
        parser.parse();

        return EXIT_SUCCESS;
    }

The parser constructor expects the char array, its length, and the handler instance. The base handler class `json_handler` implements all required handler methods. By inheriting from it, you only need to implement the handler methods you need. In this example, we are only implementing the `object_key()`, `string()`, and `number()` methods to process object key values, string values and numeric values, respectively. Refer to the `json_handler` class definition for all available handler methods.

Executing this code will generate the following output:

    JSON string: {"key1": [1,2,3,4,5], "key2": 12.3}
    object key: key1
    number: 1
    number: 2
    number: 3
    number: 4
    number: 5
    object key: key2
    number: 12.3