Sha256: af148bd03b9cdfa3e4170b1df19fb7e1e24cf205c1104c2e9c944184f9cab2f6

Contents?: true

Size: 701 Bytes

Versions: 1

Compression:

Stored size: 701 Bytes

Contents

#include <iostream>
#include <nlohmann/json.hpp>

using json = nlohmann::json;

int main()
{
    // create JSON objects
    json j_no_init_list = json::object();
    json j_empty_init_list = json::object({});
    json j_list_of_pairs = json::object({ {"one", 1}, {"two", 2} });

    // serialize the JSON objects
    std::cout << j_no_init_list << '\n';
    std::cout << j_empty_init_list << '\n';
    std::cout << j_list_of_pairs << '\n';

    // example for an exception
    try
    {
        // can only create an object from a list of pairs
        json j_invalid_object = json::object({{ "one", 1, 2 }});
    }
    catch (json::type_error& e)
    {
        std::cout << e.what() << '\n';
    }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simdjson-0.3.0 vendor/simdjson/dependencies/json/doc/examples/object.cpp