From bbf4e4626efe08e504fbbc31ae46db021f2a3306 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Sat, 9 Nov 2024 11:25:10 +0200 Subject: [PATCH] add Value::object() and Value::array() --- include/matjson3.hpp | 5 +++++ src/value.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/include/matjson3.hpp b/include/matjson3.hpp index 5702ae7..f2d251e 100644 --- a/include/matjson3.hpp +++ b/include/matjson3.hpp @@ -107,6 +107,11 @@ namespace matjson { Value(Value&&); ~Value(); + /// Create an empty JSON object + static Value object(); + /// Create an empty JSON array + static Value array(); + Value& operator=(Value); /// Parses JSON from a string diff --git a/src/value.cpp b/src/value.cpp index 54e6843..e11f1b3 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -61,6 +61,13 @@ Value::Value(Value&& other) { Value::~Value() {} +Value Value::object() { + return Value(std::make_unique(Type::Object, Array{})); +} +Value Value::array() { + return Value(std::make_unique(Type::Array, Array{})); +} + Value& Value::operator=(Value value) { if (CHECK_DUMMY_NULL) return *this; auto key = m_impl->key();