ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
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
 
JsonObjectset (const std::string &key, const JsonValue &value)
 
JsonObjectset (const std::string &key, const JsonArray &arr)
 
JsonObjectset (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 189 of file json.h.

Constructor & Destructor Documentation

◆ JsonObject()

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

Member Function Documentation

◆ empty()

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

Definition at line 222 of file json.h.

222 {
223 return keys_.empty();
224 }

◆ set() [1/3]

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

Definition at line 199 of file json.h.

199 {
200 keys_.push_back(key);
201 values_.push_back(JsonValue::fromArray(arr.toString()));
202 return *this;
203 }
static JsonValue fromArray(const std::string &serialized)
Definition json.h:96

References ascii_query::json::JsonValue::fromArray(), 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 205 of file json.h.

205 {
206 keys_.push_back(key);
207 values_.push_back(JsonValue::fromObject(obj.toString()));
208 return *this;
209 }
static JsonValue fromObject(const std::string &serialized)
Definition json.h:103

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

◆ set() [3/3]

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

Definition at line 193 of file json.h.

193 {
194 keys_.push_back(key);
195 values_.push_back(value);
196 return *this;
197 }

◆ size()

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

Definition at line 225 of file json.h.

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

◆ toString()

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

Definition at line 211 of file json.h.

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

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: