json/docs/examples/to_bon8.cpp
Niels Lohmann 88fbbd3aa8
Merge branch 'develop' of https://github.com/nlohmann/json into bon8
 Conflicts:
	docs/examples/to_bon8.cpp
	docs/examples/to_bon8.output
	docs/mkdocs/docs/api/basic_json/to_bon8.md
	include/nlohmann/detail/input/binary_reader.hpp
	include/nlohmann/detail/input/input_adapters.hpp
	include/nlohmann/detail/output/binary_writer.hpp
	single_include/nlohmann/json.hpp
	test/CMakeLists.txt
	tests/src/unit-binary_formats.cpp
	tests/src/unit-bon8.cpp
2022-05-01 18:46:44 +02:00

22 lines
466 B
C++

#include <iostream>
#include <iomanip>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create a JSON value
json j = R"({"compact": true, "schema": 0})"_json;
// serialize it to BON8
std::vector<uint8_t> v = json::to_bon8(j);
// print the vector content
for (auto& byte : v)
{
std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << (int)byte << " ";
}
std::cout << std::endl;
}