Conscience Core
json.h
Go to the documentation of this file.
1 #ifndef csc_json_H_
2 #define csc_json_H_
3 
4 #include "Util/conscience_log.h"
5 
6 #include <any>
7 #include <boost/variant.hpp>
8 #include <cstring>
9 #include <exception>
10 #include <filesystem>
11 #include <iostream>
12 #include <memory>
13 #include <optional>
14 #include <type_traits>
15 #include <typeinfo>
16 #include <yyjson.h>
17 
18 using std::string, std::optional, std::exception, std::unique_ptr, std::vector, std::any, std::make_shared;
19 namespace fs = std::filesystem;
20 template <class T>
21 using ptr = std::shared_ptr<T>;
22 
23 using namespace conscience_utils;
24 
25 namespace conscience_utils::JSON {
26 
27 #define JSON_BASE_TYPES std::nullptr_t, const char *, char *, bool, unsigned, int, long long, unsigned long long, string, float, double
28 
29 struct JsonSerializableData : boost::variant<JSON_BASE_TYPES, vector<JsonSerializableData>, map<string, JsonSerializableData>> {
30  using Vector = vector<JsonSerializableData>;
31  using Map = map<string, JsonSerializableData>;
32  using Base = boost::variant<JSON_BASE_TYPES, Vector, Map>;
33 
34  using Base::variant;
35  using Base::operator=;
36 
37  JsonSerializableData(std::initializer_list<Map::value_type> init) : Base(Map(init)) {}
38 };
39 
40 string vectorToJson(const vector<JsonSerializableData> &list, bool noNewLines = false);
41 string mapToJson(const map<string, JsonSerializableData> &entries, bool noNewLines = false);
42 string pairsToJson(const vector<pair<string, JsonSerializableData>> &entries, bool noNewLines = false);
43 string jsonSerializableDataToString(JsonSerializableData data);
44 
45 template <class TValue>
46 vector<JsonSerializableData> vectorToJsonSerializable(const vector<TValue> &theVector) {
47  vector<JsonSerializableData> vectorCopy;
48  for (auto entry : theVector) {
49  vectorCopy.push_back(entry);
50  }
51  return vectorCopy;
52 }
53 
54 template <class TValue>
55 map<string, JsonSerializableData> mapToJsonSerializable(const map<string, TValue> &map) {
56  std::map<std::string, JsonSerializableData> mapCopy;
57  for (auto entry : map) {
58  mapCopy[entry.first] = entry.second;
59  }
60  return mapCopy;
61 }
62 
63 class MissingRequiredPropertyException : public exception {
64 public:
65  MissingRequiredPropertyException(const string message) throw()
66  : message(message) {
67  }
68 
69  const char *what() const throw() {
70  return message.c_str();
71  }
72 
73  const string getMessage() const {
74  return message;
75  }
76 
77 private:
78  const string message;
79 };
80 
81 template <class T>
82 T getNumericValueFromJson(yyjson_val *jsonValue) {
83  ASSERT("given value is not numeric - " + to_string(yyjson_get_type(jsonValue)), yyjson_get_type(jsonValue) == YYJSON_TYPE_NUM);
84  switch (yyjson_get_subtype(jsonValue)) {
85  case YYJSON_SUBTYPE_UINT:
86  return (T)yyjson_get_uint(jsonValue);
87  case YYJSON_SUBTYPE_SINT:
88  return (T)yyjson_get_sint(jsonValue);
89  default:
90  case YYJSON_SUBTYPE_REAL:
91  return (T)yyjson_get_real(jsonValue);
92  }
93 }
94 
95 class CscJsonObject;
96 
101 public:
102  vector<string> getKeys();
103 
107  bool hasKey(const string &key);
108 
112  bool isArray(const string &key);
113 
117  unsigned getArrayLength(const string &arrayKey);
118 
122  bool isNull(const string &key);
123 
127  string getRequiredStringValue(const string &key, bool allowEmpty = false);
128 
132  optional<int> getIntValue(const string &key);
133 
137  int getRequiredIntValue(const string &key);
138 
142  optional<unsigned long long> getUnsignedLongValue(const string &key);
143 
147  unsigned long long getRequiredUnsignedLongValue(const string &key);
148 
149  optional<bool> getBooleanValue(const string &key);
150 
151  bool getRequiredBooleanValue(const string &key);
152 
156  optional<double> getDoubleValue(const string &key);
157 
161  double getRequiredDoubleValue(const string &key);
162 
166  optional<float> getFloatValue(const string &key);
167 
171  float getRequiredFloatValue(const string &key);
172 
176  optional<string> getStringValue(const string &key);
177 
181  CscJsonObjectReader getRequiredObjectValue(const string &key);
182 
186  optional<CscJsonObjectReader> getObjectValue(const string &key);
187 
192 
196  optional<CscJsonObjectReader *> getObjectPtrValue(const string &key);
197 
202 
206  optional<ptr<CscJsonObjectReader>> getObjectSharedPtrValue(const string &key);
207 
211  map<string, optional<any>> getRequiredObjectValueAsMap(const string &key);
212 
217  map<string, string> getRequiredObjectValueAsMapOfStrings(const string &key);
218 
222  optional<map<string, optional<any>>> getObjectValueAsMap(const string &key);
223 
227  optional<any> getAnyValue(string key);
228 
232  template <class T>
233  vector<T> getRequiredArrayValue(const string &key) {
234  optional<vector<T>> value = getArrayValue<T>(key);
235  if (!value.has_value()) {
236  throw MissingRequiredPropertyException("required array property " + key + " cannot be found in " + toString());
237  }
238 
239  return value.value();
240  }
241 
245  template <class T>
246  optional<vector<T>> getArrayValue(const string &key) {
247  try {
248  yyjson_val *value = getValueByPropertyPath(key);
249  return toArrayValue<T>(value, getYyjsonDoc());
250  } catch (const std::invalid_argument e) {
251  LOG_WARN(key + " cannot be read as array: " + string(e.what()));
252  }
253  return {};
254  }
255 
259  template <class T>
260  optional<T> getArrayItemValue(const string &arrayKey, size_t index) {
261  optional<T> result = {};
262  try {
263  yyjson_val *value = getValueByPropertyPath(arrayKey);
264  if (value != nullptr) {
265  yyjson_val *itemValue = yyjson_arr_get(value, index);
266  if (itemValue != nullptr) {
267  result = toValue<T>(itemValue, getYyjsonDoc());
268  }
269  }
270  } catch (const std::invalid_argument e) {
271  LOG_WARN("cannot getArrayItemValue " + arrayKey + " : " + string(e.what()));
272  }
273  return result;
274  }
278  template <class T>
279  T getRequiredArrayItemValue(const string &arrayKey, size_t index) {
280  optional<T> value = getArrayItemValue<T>(arrayKey, index);
281  if (!value.has_value()) {
282  throw MissingRequiredPropertyException("required array item: " + arrayKey + "[" + to_string(index) + "] cannot be found in " + toString());
283  }
284 
285  return value.value();
286  }
287 
291  template <class T>
292  vector<T> asArrayValue() {
293  return toArrayValue<T>(getYyjsonValue(), getYyjsonDoc()).value();
294  }
295 
300  CscJsonObjectReader(ptr<yyjson_doc> yyjsonDoc, yyjson_val *yyjsonValue = nullptr, bool doNotReleaseYyjsonObjects = false);
301  CscJsonObjectReader(const fs::path filePath);
302  CscJsonObjectReader(const string &jsonContent);
303 
304  virtual ~CscJsonObjectReader();
305 
306  string toString();
307 
308  string toJsonString(bool prettyPrint = false);
309 
313  CscJsonObject *toMutable(yyjson_mut_doc *parentDoc = nullptr);
314  static vector<CscJsonObject *> toMutableList(const vector<ptr<CscJsonObjectReader>> values);
315 
319  yyjson_val *getLowLevelParser();
320 
321 protected:
322  static ptr<yyjson_doc> createYyjsonSharedPtr(yyjson_doc *doc);
324 
325  yyjson_val *yyjsonValue = nullptr;
326  virtual ptr<yyjson_doc> getYyjsonDoc();
327  virtual yyjson_val *getYyjsonValue();
328 
329  yyjson_val *getValueByPropertyPath(const string &propertyPath);
330  static yyjson_doc *parseFromFile(const fs::path filePath);
331  static yyjson_doc *parseFromString(const string &jsonString);
332 
333 private:
334  const bool doNotReleaseYyjsonObjects;
335 
336  optional<any> jsonValueToAny(yyjson_val *jsonValue);
337 
338  template <class T>
339  static inline T toValue(yyjson_val *yyjsonValue, ptr<yyjson_doc> jsonDoc) {
340  if constexpr (std::is_arithmetic<T>::value) {
341  return getNumericValueFromJson<T>(yyjsonValue);
342  }
343  if constexpr (std::is_same<T, string>::value) {
344  const char *valueChars = yyjson_get_str(yyjsonValue);
345  return string(valueChars);
346  }
347  if constexpr (std::is_same_v<T, const CscJsonObjectReader *> || std::is_same_v<T, CscJsonObjectReader *>) {
348  return new CscJsonObjectReader(jsonDoc, yyjsonValue, true);
349  }
350  if constexpr (std::is_base_of<ptr<CscJsonObjectReader>, T>::value) {
351  return std::make_shared<CscJsonObjectReader>(jsonDoc, yyjsonValue, true);
352  }
353  throw new std::invalid_argument(
354  "unsupported data type " + string(typeid(T).name()) + " for array " +
355  string(yyjsonValue != nullptr ? string(yyjson_get_raw(yyjsonValue)) : "?"));
356  }
357 
358  template <class T>
359  static optional<vector<T>> toArrayValue(yyjson_val *arrayJsonValue, ptr<yyjson_doc> jsonDoc) {
360  try {
361  if (arrayJsonValue != nullptr && yyjson_get_type(arrayJsonValue) == YYJSON_TYPE_ARR) {
362  vector<T> items;
363 
364  string ss = string(yyjson_val_write(arrayJsonValue, YYJSON_WRITE_NOFLAG, NULL));
365 
366  yyjson_val *arrayItem;
367  yyjson_arr_iter iter = yyjson_arr_iter_with(arrayJsonValue);
368  while ((arrayItem = yyjson_arr_iter_next(&iter))) {
369  items.push_back(toValue<T>(arrayItem, jsonDoc));
370  }
371 
372  return items;
373  }
374  } catch (const std::invalid_argument e) {
375  LOG_WARN(string(arrayJsonValue != nullptr ? string(yyjson_get_raw(arrayJsonValue)) : "?") + " cannot be read as array: " + string(e.what()));
376  }
377  return {};
378  }
379 };
380 
382 public:
383  CscJsonParser(const fs::path &filePath);
384  CscJsonParser(const string &jsonContent);
385 };
386 
392 public:
393  CscJsonObject(const fs::path &jsonFilePath);
394  CscJsonObject(const string &jsonString);
395 
399  CscJsonObject(const map<string, string> &map);
400 
404  CscJsonObject(yyjson_mut_doc *existingDoc, yyjson_mut_val *existingValue, bool doNotReleaseYyjsonObjects = false, CscJsonObject *lookupParent = nullptr);
405 
409  CscJsonObject();
410  ~CscJsonObject();
411 
415  CscJsonObject getRequiredObjectMutableValue(const string &key);
416 
420  optional<CscJsonObject> getObjectMutableValue(const string &key);
421 
426 
430  optional<CscJsonObject *> getObjectMutablePtrValue(const string &key);
431 
436 
440  optional<ptr<CscJsonObject>> getObjectMutableSharedPtrValue(const string &key);
441 
442  CscJsonObject *set(const string &propertyPath, bool value);
443  CscJsonObject *set(const string &propertyPath, const char *value);
444  CscJsonObject *set(const string &propertyPath, const string &value);
445  CscJsonObject *set(const string &propertyPath, double value);
446  CscJsonObject *set(const string &propertyPath, int value);
447  CscJsonObject *set(const string &propertyPath, long long value);
448  CscJsonObject *set(const string &propertyPath, unsigned long long value);
449  CscJsonObject *set(const string &propertyPath, CscJsonObject &object);
453  CscJsonObject *set(const string &propertyPath, CscJsonObject *object);
454  CscJsonObject *set(const string &propertyPath, ptr<CscJsonObject> object);
455  CscJsonObject *set(const string &propertyPath, const map<string, string> &value);
456 
457  CscJsonObject *setArray(const string &propertyPath, const vector<bool> &value);
458  CscJsonObject *setArray(const string &propertyPath, const vector<string> &value);
459  CscJsonObject *setArray(const string &propertyPath, const vector<float> &value);
460  CscJsonObject *setArray(const string &propertyPath, const vector<double> &value);
461  CscJsonObject *setArray(const string &propertyPath, const vector<int> &value);
462  CscJsonObject *setArray(const string &propertyPath, const vector<long long> &value);
463  CscJsonObject *setArray(const string &propertyPath, const vector<unsigned long long> &value);
467  CscJsonObject *setArray(const string &propertyPath, const vector<CscJsonObject *> &objects);
468  CscJsonObject *setArray(const string &propertyPath, const vector<CscJsonObject> &objects);
469  CscJsonObject *setArray(const string &propertyPath, const vector<ptr<CscJsonObject>> &objects);
470  CscJsonObject *setArray(const string &propertyPath, const vector<map<string, string>> &value);
471 
475  CscJsonObject *remove(const string &propertyPath);
476 
477  void saveToFile(const fs::path &outPath, bool lineBreakAndTabulation = false);
478 
512  static string addLineBreakAndTabulation(const string &json);
513 
514  yyjson_mut_val *getLowLevelMutableObject();
515 
520  void mergeWith(CscJsonObject &other, bool deep = true);
521 
522  void mergeKeyWith(CscJsonObject &other, const string &subPropertyPath, bool deep = true);
523 
524 private:
525  bool doNotReleaseYyjsonObjects = false;
526  void onModified();
530  CscJsonObject *lookupParent = nullptr;
531 
532 protected:
540  yyjson_mut_doc *yyjsonMutableDoc = nullptr;
541 
545  yyjson_mut_val *yyjsonMutableValue = nullptr;
546 
550  virtual yyjson_val *getYyjsonValue() override;
554  virtual ptr<yyjson_doc> getYyjsonDoc() override;
558  yyjson_mut_doc *getYyjsonMutableDoc();
562  yyjson_mut_val *getYyjsonMutableValue();
563 
564  yyjson_mut_val *getMutableValueByPropertyPath(const string &propertyPath);
565 
566  yyjson_mut_val *getOrCreateObjectByPropertyPath(const string &propertyPath);
567 
568  CscJsonObject *set(const string &propertyPath, yyjson_mut_val *newValue);
569 
570  void mergeObjects(yyjson_mut_val *thisObj, yyjson_mut_val *otherObj, bool deep);
571 };
572 
573 template <class T>
574 concept IsString = std::is_same_v<T, string>;
575 template <IsString T>
576 yyjson_mut_val *toJsonValue(const T &value, yyjson_mut_doc *doc) {
577  char *stringCopy = strdup(value.c_str());
578  return yyjson_mut_str(doc, stringCopy);
579 }
580 
581 template <class T>
582 concept IsNotString = !IsString<T>;
583 template <IsNotString T>
584 yyjson_mut_val *toJsonValue(const T &value, yyjson_mut_doc *doc);
585 
586 inline yyjson_mut_val *mapToJsonObject(const map<string, string> &map, yyjson_mut_doc *doc) {
587  yyjson_mut_val *mapJsonValue = yyjson_mut_obj(doc);
588 
589  for (auto [key, value] : map) {
590  yyjson_mut_val *keyJsonValue = toJsonValue(key, doc);
591  yyjson_mut_val *valueJsonValue = toJsonValue(value, doc);
592  yyjson_mut_obj_put(mapJsonValue, keyJsonValue, valueJsonValue);
593  }
594 
595  return mapJsonValue;
596 }
597 
598 template <IsNotString T>
599 yyjson_mut_val *toJsonValue(T &value, yyjson_mut_doc *doc) {
600 
601  if constexpr (std::is_arithmetic<T>::value) {
602  if constexpr (std::is_unsigned<T>::value) {
603  return yyjson_mut_uint(doc, value);
604  } else if constexpr (std::is_floating_point<T>::value) {
605  return yyjson_mut_real(doc, value);
606  } else {
607  return yyjson_mut_sint(doc, value);
608  }
609 
610  } else if constexpr (std::is_same_v<T, bool>) {
611  return yyjson_mut_bool(doc, value);
612 
613  } else if constexpr (std::is_same_v<ptr<CscJsonObject>, T> || std::is_same_v<ptr<const CscJsonObject>, T>) {
614  return yyjson_mut_val_mut_copy(doc, value->getLowLevelMutableObject());
615 
616  } else if constexpr (std::is_same_v<CscJsonObject, T>) {
617  return yyjson_mut_val_mut_copy(doc, value.getLowLevelMutableObject());
618 
619  } else if constexpr (std::is_same_v<CscJsonObject *, T> || std::is_same_v<const CscJsonObject *, T>) {
620  return yyjson_mut_val_mut_copy(doc, value->getLowLevelMutableObject());
621 
622  } else if constexpr (std::is_same_v<map<string, string>, T>) {
623  return mapToJsonObject(value, doc);
624  } else {
625  throw runtime_error("unsupported type ");
626  }
627 }
628 
629 template <class T>
630 yyjson_mut_val *toJsonValue(const vector<T> &valueList, yyjson_mut_doc *doc, bool clone = false) {
631  yyjson_mut_val *arrayValue = yyjson_mut_arr(doc);
632  for (T value : valueList) {
633  yyjson_mut_val *jsonValue = toJsonValue<T>(value, doc);
634  yyjson_mut_val *newValue = jsonValue;
635  if (clone) {
636  newValue = yyjson_mut_val_mut_copy(doc, jsonValue);
637  }
638  bool success = yyjson_mut_arr_append(arrayValue, newValue);
639  if (!success) {
640  throw runtime_error("cannot add item to array");
641  }
642  }
643  return arrayValue;
644 }
645 
646 }
647 
648 #endif
conscience_utils::JSON::JsonSerializableData
Definition: json.h:29
conscience_utils::JSON::mapToJsonObject
yyjson_mut_val * mapToJsonObject(const map< string, string > &map, yyjson_mut_doc *doc)
Definition: json.h:586
conscience_log.h
conscience_utils::JSON::toJsonValue
yyjson_mut_val * toJsonValue(const T &value, yyjson_mut_doc *doc)
Definition: json.h:576
conscience_utils::JSON::CscJsonObjectReader::getObjectValue
optional< CscJsonObjectReader > getObjectValue(const string &key)
Definition: json.cpp:232
nlohmann::to_string
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition: json.hpp:26470
conscience_utils::JSON::CscJsonObjectReader::~CscJsonObjectReader
virtual ~CscJsonObjectReader()
Definition: json.cpp:27
conscience_utils::JSON::CscJsonObjectReader::getBooleanValue
optional< bool > getBooleanValue(const string &key)
Definition: json.cpp:152
conscience_utils::JSON::CscJsonObject::getObjectMutableValue
optional< CscJsonObject > getObjectMutableValue(const string &key)
Definition: json.cpp:881
conscience_utils::JSON::CscJsonObjectReader::getAnyValue
optional< any > getAnyValue(string key)
Definition: json.cpp:334
conscience_utils::JSON::CscJsonObjectReader::getRequiredObjectSharedPtrValue
ptr< CscJsonObjectReader > getRequiredObjectSharedPtrValue(const string &key)
Definition: json.cpp:265
conscience_utils::JSON::CscJsonObjectReader::asArrayValue
vector< T > asArrayValue()
Definition: json.h:292
conscience_utils::JSON::CscJsonObject::remove
CscJsonObject * remove(const string &propertyPath)
Definition: json.cpp:651
conscience_utils::JSON::CscJsonObject::getLowLevelMutableObject
yyjson_mut_val * getLowLevelMutableObject()
Definition: json.cpp:513
conscience_utils::JSON::CscJsonObjectReader::getRequiredObjectValue
CscJsonObjectReader getRequiredObjectValue(const string &key)
Definition: json.cpp:223
conscience_utils::JSON::CscJsonObject::getObjectMutablePtrValue
optional< CscJsonObject * > getObjectMutablePtrValue(const string &key)
Definition: json.cpp:901
conscience_utils::JSON::CscJsonObject::set
CscJsonObject * set(const string &propertyPath, bool value)
Definition: json.cpp:517
conscience_utils::JSON::CscJsonObjectReader::getYyjsonDoc
virtual ptr< yyjson_doc > getYyjsonDoc()
Definition: json.cpp:13
conscience_utils::JSON::CscJsonObjectReader::getIntValue
optional< int > getIntValue(const string &key)
Definition: json.cpp:182
conscience_utils::JSON::CscJsonObject::getRequiredObjectMutableSharedPtrValue
ptr< CscJsonObject > getRequiredObjectMutableSharedPtrValue(const string &key)
Definition: json.cpp:913
conscience_utils::JSON::CscJsonObjectReader::parseFromFile
static yyjson_doc * parseFromFile(const fs::path filePath)
Definition: json.cpp:43
conscience_utils::JSON::CscJsonObjectReader::getRequiredDoubleValue
double getRequiredDoubleValue(const string &key)
Definition: json.cpp:113
conscience_utils::JSON::CscJsonObject::~CscJsonObject
~CscJsonObject()
Definition: json.cpp:452
conscience_utils::JSON::CscJsonObjectReader::getObjectSharedPtrValue
optional< ptr< CscJsonObjectReader > > getObjectSharedPtrValue(const string &key)
Definition: json.cpp:274
conscience_utils::JSON::CscJsonObject::getRequiredObjectMutablePtrValue
CscJsonObject * getRequiredObjectMutablePtrValue(const string &key)
Definition: json.cpp:892
conscience_utils::JSON::CscJsonObjectReader::CscJsonObjectReader
CscJsonObjectReader(ptr< yyjson_doc > yyjsonDoc, yyjson_val *yyjsonValue=nullptr, bool doNotReleaseYyjsonObjects=false)
Definition: json.cpp:9
conscience_utils::JSON::CscJsonObjectReader::getLowLevelParser
yyjson_val * getLowLevelParser()
Definition: json.cpp:286
conscience_utils::JSON::CscJsonObjectReader::getArrayValue
optional< vector< T > > getArrayValue(const string &key)
Definition: json.h:246
conscience_utils::JSON::CscJsonObject::getYyjsonMutableDoc
yyjson_mut_doc * getYyjsonMutableDoc()
Definition: json.cpp:488
conscience_utils::JSON::JsonSerializableData::JsonSerializableData
JsonSerializableData(std::initializer_list< Map::value_type > init)
Definition: json.h:37
conscience_utils::JSON::CscJsonObject::getYyjsonMutableValue
yyjson_mut_val * getYyjsonMutableValue()
Definition: json.cpp:501
conscience_utils::JSON::CscJsonObjectReader::toMutableList
static vector< CscJsonObject * > toMutableList(const vector< ptr< CscJsonObjectReader >> values)
Definition: json.cpp:864
conscience_utils::JSON::IsNotString
concept IsNotString
Definition: json.h:582
conscience_utils::JSON::CscJsonObjectReader::yyjsonDoc
ptr< yyjson_doc > yyjsonDoc
Definition: json.h:323
conscience_utils::JSON::CscJsonObjectReader::parseFromString
static yyjson_doc * parseFromString(const string &jsonString)
Definition: json.cpp:53
conscience_utils::JSON::getNumericValueFromJson
T getNumericValueFromJson(yyjson_val *jsonValue)
Definition: json.h:82
conscience_utils::JSON::CscJsonObject::yyjsonMutableDoc
yyjson_mut_doc * yyjsonMutableDoc
Definition: json.h:540
conscience_utils::JSON::MissingRequiredPropertyException::MissingRequiredPropertyException
MissingRequiredPropertyException(const string message)
Definition: json.h:65
conscience_utils::JSON::CscJsonObjectReader::toString
string toString()
Definition: json.cpp:30
conscience_utils::JSON::jsonSerializableDataToString
string jsonSerializableDataToString(JsonSerializableData data)
Definition: json.cpp:750
conscience_utils::JSON::CscJsonObject::mergeKeyWith
void mergeKeyWith(CscJsonObject &other, const string &subPropertyPath, bool deep=true)
Definition: json.cpp:943
conscience_utils::JSON::CscJsonObjectReader::getRequiredUnsignedLongValue
unsigned long long getRequiredUnsignedLongValue(const string &key)
Definition: json.cpp:92
conscience_utils::JSON::CscJsonObjectReader::getArrayItemValue
optional< T > getArrayItemValue(const string &arrayKey, size_t index)
Definition: json.h:260
nlohmann::detail::value_t::string
@ string
string value
conscience_utils::JSON::CscJsonObjectReader::createYyjsonSharedPtr
static ptr< yyjson_doc > createYyjsonSharedPtr(yyjson_doc *doc)
Definition: json.cpp:290
conscience_utils::JSON::CscJsonObjectReader::yyjsonValue
yyjson_val * yyjsonValue
Definition: json.h:325
conscience_utils::JSON::CscJsonObject::getMutableValueByPropertyPath
yyjson_mut_val * getMutableValueByPropertyPath(const string &propertyPath)
Definition: json.cpp:357
conscience_utils::JSON::CscJsonObject::yyjsonMutableValue
yyjson_mut_val * yyjsonMutableValue
Definition: json.h:545
conscience_utils::JSON::CscJsonObjectReader::toJsonString
string toJsonString(bool prettyPrint=false)
Definition: json.cpp:34
LOG_WARN
#define LOG_WARN(message)
Definition: conscience_log.h:193
conscience_utils::JSON::CscJsonObject::getOrCreateObjectByPropertyPath
yyjson_mut_val * getOrCreateObjectByPropertyPath(const string &propertyPath)
Definition: json.cpp:620
conscience_utils::JSON::CscJsonObjectReader::hasKey
bool hasKey(const string &key)
Definition: json.cpp:134
conscience_utils::JSON::CscJsonObject::addLineBreakAndTabulation
static string addLineBreakAndTabulation(const string &json)
Adds line breaks and tabulations to a JSON string for improved readability.
Definition: json.cpp:679
conscience_utils::JSON::CscJsonParser::CscJsonParser
CscJsonParser(const fs::path &filePath)
Definition: json.cpp:422
conscience_utils::JSON::CscJsonObject::getObjectMutableSharedPtrValue
optional< ptr< CscJsonObject > > getObjectMutableSharedPtrValue(const string &key)
Definition: json.cpp:922
conscience_utils::JSON::vectorToJson
string vectorToJson(const vector< JsonSerializableData > &list, bool noNewLines)
Definition: json.cpp:812
conscience_utils::JSON
Definition: CscCommandMetadataBuilder.h:20
conscience_utils::JSON::JsonSerializableData::Vector
vector< JsonSerializableData > Vector
Definition: json.h:30
conscience_utils::JSON::CscJsonObject::saveToFile
void saveToFile(const fs::path &outPath, bool lineBreakAndTabulation=false)
Definition: json.cpp:662
conscience_utils::JSON::CscJsonObject::CscJsonObject
CscJsonObject()
Definition: json.cpp:449
jwt::alphabet::index
uint32_t index(const std::array< char, 64 > &alphabet, char symbol)
Definition: base.h:91
conscience_utils::JSON::pairsToJson
string pairsToJson(const vector< pair< string, JsonSerializableData >> &entries, bool noNewLines)
Definition: json.cpp:827
conscience_utils::JSON::mapToJson
string mapToJson(const map< string, JsonSerializableData > &map, bool noNewLines)
Definition: json.cpp:734
conscience_utils::JSON::CscJsonObjectReader::getRequiredBooleanValue
bool getRequiredBooleanValue(const string &key)
Definition: json.cpp:164
conscience_core::bridging::commands::environment_objects::optional< double >
const ptr< CscObjectModel > const string const CscPoint3d const CscPoint3d optional< double >
Definition: environmentObjectsCommands.h:367
conscience_utils::JSON::CscJsonParser
Definition: json.h:381
conscience_utils::JSON::IsString
concept IsString
Definition: json.h:574
conscience_utils::JSON::MissingRequiredPropertyException::getMessage
const string getMessage() const
Definition: json.h:73
conscience_utils
Definition: CscEntityReflexion.h:50
conscience_utils::JSON::CscJsonObject::mergeWith
void mergeWith(CscJsonObject &other, bool deep=true)
Definition: json.cpp:934
conscience_utils::JSON::CscJsonObject::getYyjsonDoc
virtual ptr< yyjson_doc > getYyjsonDoc() override
Definition: json.cpp:464
conscience_utils::JSON::CscJsonObject::getYyjsonValue
virtual yyjson_val * getYyjsonValue() override
Definition: json.cpp:478
conscience_utils::JSON::CscJsonObjectReader::isNull
bool isNull(const string &key)
Definition: json.cpp:64
conscience_utils::JSON::CscJsonObjectReader::isArray
bool isArray(const string &key)
Definition: json.cpp:139
conscience_utils::JSON::CscJsonObjectReader::getDoubleValue
optional< double > getDoubleValue(const string &key)
Definition: json.cpp:101
conscience_utils::JSON::CscJsonObjectReader::getRequiredObjectValueAsMap
map< string, optional< any > > getRequiredObjectValueAsMap(const string &key)
Definition: json.cpp:296
conscience_utils::JSON::vectorToJsonSerializable
vector< JsonSerializableData > vectorToJsonSerializable(const vector< TValue > &theVector)
Definition: json.h:46
conscience_utils::JSON::CscJsonObjectReader::getRequiredObjectPtrValue
CscJsonObjectReader * getRequiredObjectPtrValue(const string &key)
Definition: json.cpp:244
conscience_utils::JSON::CscJsonObjectReader::getRequiredArrayItemValue
T getRequiredArrayItemValue(const string &arrayKey, size_t index)
Definition: json.h:279
conscience_utils::JSON::CscJsonObjectReader::toMutable
CscJsonObject * toMutable(yyjson_mut_doc *parentDoc=nullptr)
Definition: json.cpp:853
conscience_utils::JSON::CscJsonObjectReader::getYyjsonValue
virtual yyjson_val * getYyjsonValue()
Definition: json.cpp:17
conscience_utils::JSON::CscJsonObjectReader::getRequiredObjectValueAsMapOfStrings
map< string, string > getRequiredObjectValueAsMapOfStrings(const string &key)
Definition: json.cpp:325
conscience_utils::JSON::MissingRequiredPropertyException::what
const char * what() const
Definition: json.h:69
conscience_utils::JSON::CscJsonObject::setArray
CscJsonObject * setArray(const string &propertyPath, const vector< bool > &value)
Definition: json.cpp:556
conscience_utils::JSON::JsonSerializableData::Base
boost::variant< JSON_BASE_TYPES, Vector, Map > Base
Definition: json.h:32
conscience_utils::JSON::CscJsonObjectReader::getRequiredArrayValue
vector< T > getRequiredArrayValue(const string &key)
Definition: json.h:233
conscience_utils::JSON::CscJsonObjectReader::getRequiredFloatValue
float getRequiredFloatValue(const string &key)
Definition: json.cpp:130
conscience_utils::JSON::CscJsonObjectReader::getValueByPropertyPath
yyjson_val * getValueByPropertyPath(const string &propertyPath)
Definition: json.cpp:352
ASSERT
#define ASSERT(MSG, EXPR)
Definition: conscience_util.h:43
conscience_utils::JSON::CscJsonObjectReader
Definition: json.h:100
conscience_utils::JSON::CscJsonObject
Definition: json.h:391
conscience_utils::JSON::CscJsonObjectReader::getUnsignedLongValue
optional< unsigned long long > getUnsignedLongValue(const string &key)
Definition: json.cpp:194
conscience_utils::JSON::CscJsonObject::getRequiredObjectMutableValue
CscJsonObject getRequiredObjectMutableValue(const string &key)
Definition: json.cpp:872
conscience_utils::JSON::CscJsonObjectReader::getFloatValue
optional< float > getFloatValue(const string &key)
Definition: json.cpp:122
conscience_core::bridging::commands::environment_objects::optional< string >
const ptr< CscObjectModel > const string const CscPoint3d const CscPoint3d optional< string >
Definition: environmentObjectsCommands.h:373
conscience_utils::JSON::CscJsonObjectReader::getObjectPtrValue
optional< CscJsonObjectReader * > getObjectPtrValue(const string &key)
Definition: json.cpp:253
conscience_utils::JSON::CscJsonObjectReader::getRequiredIntValue
int getRequiredIntValue(const string &key)
Definition: json.cpp:83
conscience_utils::JSON::JsonSerializableData::Map
map< string, JsonSerializableData > Map
Definition: json.h:31
conscience_utils::JSON::CscJsonObjectReader::getObjectValueAsMap
optional< map< string, optional< any > > > getObjectValueAsMap(const string &key)
Definition: json.cpp:305
ptr
std::shared_ptr< T > ptr
Definition: CscCommon.h:29
conscience_utils::JSON::CscJsonObjectReader::getRequiredStringValue
string getRequiredStringValue(const string &key, bool allowEmpty=false)
Definition: json.cpp:173
conscience_utils::JSON::CscJsonObject::mergeObjects
void mergeObjects(yyjson_mut_val *thisObj, yyjson_mut_val *otherObj, bool deep)
Definition: json.cpp:955
conscience_utils::JSON::MissingRequiredPropertyException
Definition: json.h:63
conscience_utils::JSON::CscJsonObjectReader::getStringValue
optional< string > getStringValue(const string &key)
Definition: json.cpp:206
conscience_utils::JSON::CscJsonObjectReader::getKeys
vector< string > getKeys()
Definition: json.cpp:69
conscience_utils::JSON::mapToJsonSerializable
map< string, JsonSerializableData > mapToJsonSerializable(const map< string, TValue > &map)
Definition: json.h:55
conscience_utils::JSON::CscJsonObjectReader::getArrayLength
unsigned getArrayLength(const string &arrayKey)
Definition: json.cpp:144