mirror of
https://github.com/nlohmann/json
synced 2024-11-22 03:50:05 +00:00
e3095f636f
* Add operator<< for json_pointer * Deprecate json_pointer::operator string_t() * Update documentation * Move operator<<(basic_json) example * Add example * Add mkdocs-redirects * Move operator<< and operator>> doc pages out of basic_json/ * Rename JSON pointer operator_string to operator_string_t * Add unit test
22 lines
549 B
C++
22 lines
549 B
C++
#include <iostream>
|
|
#include <iomanip>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
using json = nlohmann::json;
|
|
|
|
int main()
|
|
{
|
|
// create JSON values
|
|
json j_object = {{"one", 1}, {"two", 2}};
|
|
json j_array = {1, 2, 4, 8, 16};
|
|
|
|
// serialize without indentation
|
|
std::cout << j_object << "\n\n";
|
|
std::cout << j_array << "\n\n";
|
|
|
|
// serialize with indentation
|
|
std::cout << std::setw(4) << j_object << "\n\n";
|
|
std::cout << std::setw(2) << j_array << "\n\n";
|
|
std::cout << std::setw(1) << std::setfill('\t') << j_object << "\n\n";
|
|
}
|