From 290672d7b4b3c454f02a42d95df3ddfae307542f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 15 Oct 2025 00:15:31 +0200 Subject: Use nlohmann for JSON. --- src/lib/http_server.cc | 12 ++++++------ src/lib/wscript | 2 +- 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 #include #include @@ -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 3489aab7b..4478c2587 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -258,7 +258,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: diff --git a/wscript b/wscript index 1b2e83dac..e4925366c 100644 --- a/wscript +++ b/wscript @@ -697,6 +697,14 @@ def configure(conf): define_name="DCPOMATIC_HAVE_SQLITE3_PREPARE_V3", mandatory=False) + conf.check_cxx(fragment=""" + #include + int main() { nlohmann::json json; return 0; } + """, + msg='Checking for nlohmann json', + uselib='JSON', + mandatory=True) + # Other stuff -- cgit v1.2.3