ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
ascii_query::json::JsonObject Class Reference

JSON object builder. More...

#include <src/tooling/query/json.h>

Public Member Functions

 JsonObject ()=default
JsonObject & set (const std::string &key, const JsonValue &value)
JsonObject & set (const std::string &key, const JsonArray &arr)
JsonObject & set (const std::string &key, const JsonObject &obj)
std::string toString () const
bool empty () const
size_t size () const

Detailed Description

JSON object builder.

Definition at line 192 of file src/tooling/query/json.h.

Constructor & Destructor Documentation

◆ JsonObject()

ascii_query::json::JsonObject::JsonObject ( )
default

Referenced by set(), set(), and set().

Member Function Documentation

◆ empty()

bool ascii_query::json::JsonObject::empty ( ) const
inlinenodiscard

Definition at line 225 of file src/tooling/query/json.h.

225 {
226 return keys_.empty();
227 }

◆ set() [1/3]

JsonObject & ascii_query::json::JsonObject::set ( const std::string & key,
const JsonArray & arr )
inline

Definition at line 202 of file src/tooling/query/json.h.

202 {
203 keys_.push_back(key);
204 values_.push_back(JsonValue::fromArray(arr.toString()));
205 return *this;
206 }
static JsonValue fromArray(const std::string &serialized)

References ascii_query::json::JsonValue::fromArray(), JsonObject(), and ascii_query::json::JsonArray::toString().

◆ set() [2/3]

JsonObject & ascii_query::json::JsonObject::set ( const std::string & key,
const JsonObject & obj )
inline

Definition at line 208 of file src/tooling/query/json.h.

208 {
209 keys_.push_back(key);
210 values_.push_back(JsonValue::fromObject(obj.toString()));
211 return *this;
212 }
static JsonValue fromObject(const std::string &serialized)

References ascii_query::json::JsonValue::fromObject(), JsonObject(), and toString().

◆ set() [3/3]

JsonObject & ascii_query::json::JsonObject::set ( const std::string & key,
const JsonValue & value )
inline

Definition at line 196 of file src/tooling/query/json.h.

196 {
197 keys_.push_back(key);
198 values_.push_back(value);
199 return *this;
200 }

References JsonObject().

◆ size()

size_t ascii_query::json::JsonObject::size ( ) const
inlinenodiscard

Definition at line 228 of file src/tooling/query/json.h.

228 {
229 return keys_.size();
230 }

◆ toString()

std::string ascii_query::json::JsonObject::toString ( ) const
inlinenodiscard

Definition at line 214 of file src/tooling/query/json.h.

214 {
215 std::string result = "{";
216 for (size_t i = 0; i < keys_.size(); i++) {
217 if (i > 0)
218 result += ",";
219 result += "\"" + escape(keys_[i]) + "\":" + values_[i].toString();
220 }
221 result += "}";
222 return result;
223 }
std::string escape(const std::string &str)
Escape a string for JSON output.

References ascii_query::json::escape().

Referenced by ascii_query::json::JsonArray::add(), and set().


The documentation for this class was generated from the following file: