Skip to content

Latest commit

 

History

History
36 lines (29 loc) · 631 Bytes

README.md

File metadata and controls

36 lines (29 loc) · 631 Bytes

JSON

This repository contains a JSON parser and generator written in C++.

Read a JSON from a string

#include "json.hpp"
#include <iostream>

int main()
{
    std::string json_string = "{\"key\": \"value\"}";
    json::json j = json::load(json_string);
    std::cout << j["key"] << std::endl;
    return 0;
}

Write a JSON to a string

#include "json.hpp"
#include <iostream>

int main()
{
    json::json j;
    j["key"] = "value";
    j["number"] = 42;
    j["array"] = {1, 2, 3};
    j["object"] = {{"key", "value"}};
    std::cout << j.dump() << std::endl;
    return 0;
}