9static const char *
const TAG =
"json";
21 JsonObject root = builder.
root();
29 return parse_json(
reinterpret_cast<const uint8_t *
>(data.c_str()), data.size(), f);
35 if (doc.overflowed() || doc.isNull())
37 return f(doc.as<JsonObject>());
43 if (data ==
nullptr ||
len == 0) {
44 ESP_LOGE(TAG,
"No data to parse");
48 JsonDocument json_document(&global_json_allocator);
50 JsonDocument json_document;
52 if (json_document.overflowed()) {
53 ESP_LOGE(TAG,
"Could not allocate memory for JSON document!");
56 DeserializationError err = deserializeJson(json_document, data,
len);
58 if (err == DeserializationError::Ok) {
60 }
else if (err == DeserializationError::NoMemory) {
61 ESP_LOGE(TAG,
"Can not allocate more memory for deserialization. Consider making source string smaller");
64 ESP_LOGE(TAG,
"Parse error: %s", err.c_str());
70 if (doc_.overflowed()) {
71 ESP_LOGE(TAG,
"JSON document overflow");
75 serializeJson(doc_, output);
Builder class for creating JSON documents without lambdas.
std::function< void(JsonObject)> json_build_t
Callback function typedef for building JsonObjects.
bool parse_json(const std::string &data, const json_parse_t &f)
Parse a JSON string and run the provided json parse function if it's valid.
std::string build_json(const json_build_t &f)
Build a JSON string with the provided json build function.
std::function< bool(JsonObject)> json_parse_t
Callback function typedef for parsing JsonObjects.
Providing packet encoding functions for exchanging data with a remote host.