9static const char *
const TAG =
"json";
14 JsonObject root = builder.
root();
23 if (doc.overflowed() || doc.isNull())
25 return f(doc.as<JsonObject>());
33 JsonDocument json_document(&doc_allocator);
35 JsonDocument json_document;
37 if (json_document.overflowed()) {
38 ESP_LOGE(TAG,
"Could not allocate memory for JSON document!");
41 DeserializationError err = deserializeJson(json_document, data);
43 if (err == DeserializationError::Ok) {
45 }
else if (err == DeserializationError::NoMemory) {
46 ESP_LOGE(TAG,
"Can not allocate more memory for deserialization. Consider making source string smaller");
49 ESP_LOGE(TAG,
"Parse error: %s", err.c_str());
55 if (doc_.overflowed()) {
56 ESP_LOGE(TAG,
"JSON document overflow");
60 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.