summaryrefslogtreecommitdiff
path: root/tomlplusplus/examples/toml_to_json_transcoder.cpp
diff options
context:
space:
mode:
authorMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:44:05 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:44:05 +0300
commit0b24459ac12b6cf9fd5a401d647796ca254a8fa8 (patch)
treef2fd66e2476976a51e2a51330fd95dc6e87b24c1 /tomlplusplus/examples/toml_to_json_transcoder.cpp
parentb85e90fc3480da0e6a48da73201a0b22488cc650 (diff)
parent1c8b7466e4946fcc3bf20484c0e1d001202cca5a (diff)
downloadProject-Tick-0b24459ac12b6cf9fd5a401d647796ca254a8fa8.tar.gz
Project-Tick-0b24459ac12b6cf9fd5a401d647796ca254a8fa8.zip
Add 'tomlplusplus/' from commit '1c8b7466e4946fcc3bf20484c0e1d001202cca5a'
git-subtree-dir: tomlplusplus git-subtree-mainline: b85e90fc3480da0e6a48da73201a0b22488cc650 git-subtree-split: 1c8b7466e4946fcc3bf20484c0e1d001202cca5a
Diffstat (limited to 'tomlplusplus/examples/toml_to_json_transcoder.cpp')
-rw-r--r--tomlplusplus/examples/toml_to_json_transcoder.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/tomlplusplus/examples/toml_to_json_transcoder.cpp b/tomlplusplus/examples/toml_to_json_transcoder.cpp
new file mode 100644
index 0000000000..f47143b6b4
--- /dev/null
+++ b/tomlplusplus/examples/toml_to_json_transcoder.cpp
@@ -0,0 +1,36 @@
+// This file is a part of toml++ and is subject to the the terms of the MIT license.
+// Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
+// See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
+// SPDX-License-Identifier: MIT
+
+// This example demonstrates how to use the toml::json_formatter to re-serialize TOML data as JSON.
+
+#include "examples.hpp"
+#include <toml++/toml.hpp>
+
+using namespace std::string_view_literals;
+
+int main(int argc, char** argv)
+{
+ const auto path = argc > 1 ? std::string_view{ argv[1] } : ""sv;
+
+ toml::table table;
+ try
+ {
+ // read directly from stdin
+ if (path == "-"sv || path.empty())
+ table = toml::parse(std::cin, "stdin"sv);
+
+ // read from a file
+ else
+ table = toml::parse_file(argv[1]);
+ }
+ catch (const toml::parse_error& err)
+ {
+ std::cerr << err << "\n";
+ return 1;
+ }
+
+ std::cout << toml::json_formatter{ table } << "\n";
+ return 0;
+}