diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-10-15 00:15:31 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2026-02-16 01:20:17 +0100 |
| commit | 290672d7b4b3c454f02a42d95df3ddfae307542f (patch) | |
| tree | cf5531f768b86e40a7ba41743b6ec30e00249e7c | |
| parent | e23af8c3cf898dd443de7e081542f039f6763cec (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 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: @@ -697,6 +697,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 |
