RAVENNAKIT
Loading...
Searching...
No Matches
json.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-or-later
2/*
3 * Project: RAVENNAKIT (RAVENNA / AES67 / ST2110-30 SDK)
4 * Copyright (c) 2024-2025 Sound on Digital
5 *
6 * This file is part of RAVENNAKIT.
7 *
8 * RAVENNAKIT is dual-licensed:
9 * 1) Under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version (the "AGPL License"); and
12 * 2) Under a commercial license from Sound on Digital, for customers who
13 * cannot (or do not wish to) comply with the AGPL License terms.
14 *
15 * If you obtained this file under the AGPL License, you may redistribute it
16 * and/or modify it under the terms of the AGPL License. See the LICENSE
17 * file in the project root for details.
18 *
19 * For commercial licensing, support, and other inquiries, please visit:
20 *
21 * https://ravennakit.com
22 *
23 */
24
25#pragma once
26
27#ifndef RAV_ENABLE_JSON
28 #define RAV_ENABLE_JSON
29#endif
30
31#ifdef RAV_ENABLE_JSON
32 #include "expected.hpp"
33
34 #define RAV_HAS_BOOST_JSON 1
35 #include <boost/json.hpp>
36 #include <boost/json/value_to.hpp> // Don't remove or suffer the errors
37 #include <boost/json/value_from.hpp> // Don't remove or suffer the errors
38#else
39 #define RAV_HAS_BOOST_JSON 0
40#endif
41
42namespace rav {
43
44#if RAV_HAS_BOOST_JSON
45
46template<typename T>
47boost::system::result<T> parse_json(const std::string_view json_str) {
48 boost::system::error_code ec;
49 const auto jv = boost::json::parse(json_str, ec);
50 if (ec) {
51 return ec;
52 }
53 return boost::json::try_value_to<T>(jv);
54}
55
56#endif
57
58} // namespace rav
boost::system::result< T > parse_json(const std::string_view json_str)
Definition json.hpp:47