aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_json.cc
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2024-02-09 14:09:08 +0100
committerm-holger <m-holger@kubitscheck.org>2024-02-16 11:51:25 +0100
commite2737ab646bff6aa07ba72e0cc15cc955d9afcc0 (patch)
tree0ff6b1adb00694477e23e278055d61474d6b844a /libqpdf/QPDF_json.cc
parent9e90007a4a490dd1335b63079fc3e2a74420911f (diff)
downloadqpdf-e2737ab646bff6aa07ba72e0cc15cc955d9afcc0.tar.zst
Add new writeJSON methods
Create an alternative to getJSON to allow an object handle to be written as JSON without the overhead of creating a JSON object.
Diffstat (limited to 'libqpdf/QPDF_json.cc')
-rw-r--r--libqpdf/QPDF_json.cc13
1 files changed, 10 insertions, 3 deletions
diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc
index 8326e6a5..5560afec 100644
--- a/libqpdf/QPDF_json.cc
+++ b/libqpdf/QPDF_json.cc
@@ -1,6 +1,7 @@
#include <qpdf/QPDF.hh>
#include <qpdf/FileInputSource.hh>
+#include <qpdf/JSON_writer.hh>
#include <qpdf/Pl_Base64.hh>
#include <qpdf/Pl_StdioFile.hh>
#include <qpdf/QIntC.hh>
@@ -864,9 +865,15 @@ void
QPDF::writeJSONObject(
int version, Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle& obj)
{
- auto j = JSON::makeDictionary();
- j.addDictionaryMember("value", obj.getJSON(version, true));
- JSON::writeDictionaryItem(p, first, key, j, 3);
+ if (first) {
+ *p << "\n \"" << key << "\": {\n \"value\": ";
+ first = false;
+ } else {
+ *p << ",\n \"" << key << "\": {\n \"value\": ";
+ }
+ auto w = JSON::Writer(p, 4);
+ obj.writeJSON(version, w, true);
+ *p << "\n }";
}
void