diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-10-15 00:15:31 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2026-04-25 12:55:25 +0200 |
| commit | ec065f28d04c03e134e36d4b9ef520f1e9620de8 (patch) | |
| tree | 63aa8682a87e902b0758cd305507c63bc1d2197a | |
| parent | 57cdd6f6b9d4fd5d0a2d0bce03c60e8f9bd7d735 (diff) | |
Use nlohmann for JSON.
| -rw-r--r-- | src/lib/http_server.cc | 12 | ||||
| -rw-r--r-- | src/lib/wscript | 2 | ||||
| -rw-r--r-- | wscript | 8 |
3 files changed, 15 insertions, 7 deletions
diff --git a/src/lib/http_server.cc b/src/lib/http_server.cc index 3dab26d1e..294d350ac 100644 --- a/src/lib/http_server.cc +++ b/src/lib/http_server.cc @@ -25,6 +25,7 @@ #include "http_server.h" #include "util.h" #include "variant.h" +#include <nlohmann/json.hpp> #include <boost/algorithm/string.hpp> #include <stdexcept> @@ -96,15 +97,14 @@ HTTPServer::get(string const& url) if (url == "/") { return Response(200, fmt::format(dcp::file_to_string(resources_path() / "web" / "index.html"), variant::dcpomatic_player())); } else if (url == "/api/v1/status") { - auto json = string{"{ "}; + nlohmann::json json; { boost::mutex::scoped_lock lm(_mutex); - json += fmt::format("\"playing\": {}, ", _playing ? "true" : "false"); - json += fmt::format("\"position\": \"{}\", ", seconds_to_hms(_position.seconds())); - json += fmt::format("\"dcp_name\": \"{}\"", _dcp_name); + json["playing"] = _playing; + json["position"] = seconds_to_hms(_position.seconds()); + json["dcp_name"] = _dcp_name; } - json += " }"; - auto response = Response(200, json); + auto response = Response(200, json.dump()); response.set_type(Response::Type::JSON); return response; } else { diff --git a/src/lib/wscript b/src/lib/wscript index 28a76c8fd..4761648a4 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -261,7 +261,7 @@ def build(bld): BOOST_FILESYSTEM BOOST_THREAD BOOST_DATETIME BOOST_SIGNALS2 BOOST_REGEX SAMPLERATE POSTPROC TIFF SSH DCP CXML GLIB LZMA XML++ CURL ZIP BZ2 FONTCONFIG PANGOMM CAIROMM XMLSEC SUB ICU NETTLE PNG JPEG LEQM_NRT - LIBZ SQLITE3 + LIBZ SQLITE3 JSON """ if bld.env.TARGET_OSX: @@ -698,6 +698,14 @@ def configure(conf): define_name="DCPOMATIC_HAVE_SQLITE3_PREPARE_V3", mandatory=False) + conf.check_cxx(fragment=""" + #include <nlohmann/json.hpp> + int main() { nlohmann::json json; return 0; } + """, + msg='Checking for nlohmann json', + uselib='JSON', + mandatory=True) + # Other stuff |
