summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-10-21 23:15:15 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-10-21 23:15:29 +0200
commit8377be960d5d0e65227cc179aded1f5edbf8de79 (patch)
tree88f69696e2b723cdcb11e7acd914c55624645e57
parente0a0365383a3baf1a13b68c476421a85d29a244b (diff)
json: Add support for null
-rw-r--r--src/json.cc10
-rw-r--r--src/json.hh1
2 files changed, 11 insertions, 0 deletions
diff --git a/src/json.cc b/src/json.cc
index 46ea513..e8ddf52 100644
--- a/src/json.cc
+++ b/src/json.cc
@@ -62,6 +62,11 @@ class BaseWriter : public Writer {
write(value);
}
+ void value(std::nullptr_t) override {
+ before_value();
+ write(nullptr);
+ }
+
void start_array() override {
before_value();
stack_.emplace_back(StackEntry::Type::kArray);
@@ -125,6 +130,7 @@ class BaseWriter : public Writer {
virtual void write(bool value) = 0;
virtual void write(char value) = 0;
virtual void write(std::string_view value) = 0;
+ virtual void write(std::nullptr_t) = 0;
void write(char const* value) { this->write(std::string_view(value)); }
@@ -225,6 +231,8 @@ class IosWriter : public BaseWriter {
void write(char value) override { out_ << value; }
+ void write(std::nullptr_t) override { out_ << "null"; }
+
private:
std::ostream& out_;
};
@@ -275,6 +283,8 @@ class StringWriter : public BaseWriter {
void write(char value) override { out_.push_back(value); }
+ void write(std::nullptr_t) override { out_.append("null"); }
+
void clear() override {
BaseWriter::clear();
out_.clear();
diff --git a/src/json.hh b/src/json.hh
index 609fc80..f2aae92 100644
--- a/src/json.hh
+++ b/src/json.hh
@@ -19,6 +19,7 @@ class Writer {
virtual void value(float value) = 0;
virtual void value(double value) = 0;
virtual void value(bool value) = 0;
+ virtual void value(std::nullptr_t) = 0;
void value(char const* value);
void value(int32_t value);