2020-04-11 16:43:38 +00:00
|
|
|
// This file is a part of toml++ and is subject to the the terms of the MIT license.
|
2021-01-02 15:48:47 +00:00
|
|
|
// Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
|
2020-04-11 16:43:38 +00:00
|
|
|
// See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2021-05-21 11:28:45 +00:00
|
|
|
// This example demonstrates how to use the toml::json_formatter to re-serialize TOML data as JSON.
|
2020-04-11 16:43:38 +00:00
|
|
|
|
2021-05-21 11:28:45 +00:00
|
|
|
#include "examples.h"
|
2020-06-28 22:57:59 +00:00
|
|
|
|
2021-10-30 14:26:05 +00:00
|
|
|
#define TOML_ENABLE_UNRELEASED_FEATURES 1
|
2020-02-22 14:10:32 +00:00
|
|
|
#include <toml++/toml.h>
|
2020-06-28 22:57:59 +00:00
|
|
|
|
2020-01-06 18:21:16 +00:00
|
|
|
using namespace std::string_view_literals;
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2021-05-21 11:28:45 +00:00
|
|
|
toml::table table;
|
|
|
|
try
|
2020-01-06 18:21:16 +00:00
|
|
|
{
|
2021-05-21 11:28:45 +00:00
|
|
|
// read from a file if a path argument is given
|
|
|
|
if (argc > 1)
|
|
|
|
table = toml::parse_file(argv[1]);
|
|
|
|
|
|
|
|
// otherwise read directly from stdin
|
|
|
|
else
|
|
|
|
table = toml::parse(std::cin, "stdin"sv);
|
|
|
|
|
|
|
|
std::cout << toml::json_formatter{ table } << "\n";
|
|
|
|
}
|
|
|
|
catch (const toml::parse_error& err)
|
2020-01-06 18:21:16 +00:00
|
|
|
{
|
2021-05-21 11:28:45 +00:00
|
|
|
std::cerr << err << "\n";
|
|
|
|
return 1;
|
2020-01-06 18:21:16 +00:00
|
|
|
}
|
|
|
|
|
2021-05-21 11:28:45 +00:00
|
|
|
std::cout << toml::json_formatter{ table } << "\n";
|
2020-01-06 18:21:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|