From 995ab7233d50fe999fdc90e89cf17dfc4495772c Mon Sep 17 00:00:00 2001 From: nename0 <26363498+nename0@users.noreply.github.com> Date: Sun, 7 Sep 2025 11:25:17 +0200 Subject: [PATCH] Add "keys" for nested values in scheduler HTTP response --- src/core/shuntingYard.hpp | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/core/shuntingYard.hpp b/src/core/shuntingYard.hpp index eef73466a..14a993e19 100644 --- a/src/core/shuntingYard.hpp +++ b/src/core/shuntingYard.hpp @@ -697,7 +697,7 @@ std::string compute(const std::string & expr) { JsonDocument doc; if (DeserializationError::Ok == deserializeJson(doc, cmd)) { HTTPClient http; - std::string url, header_s, value_s, method_s, key_s; + std::string url, header_s, value_s, method_s, key_s, keys_s; // search keys lower case for (JsonPair p : doc.as()) { if (emsesp::Helpers::toLower(p.key().c_str()) == "url") { @@ -709,7 +709,11 @@ std::string compute(const std::string & expr) { } else if (emsesp::Helpers::toLower(p.key().c_str()) == "method") { method_s = p.key().c_str(); } else if (emsesp::Helpers::toLower(p.key().c_str()) == "key") { - key_s = p.key().c_str(); + keys_s = ""; + key_s = p.key().c_str(); + } else if (emsesp::Helpers::toLower(p.key().c_str()) == "keys") { + key_s = ""; + keys_s = p.key().c_str(); } } if (http.begin(url.c_str())) { @@ -731,12 +735,33 @@ std::string compute(const std::string & expr) { } if (httpResult > 0) { - std::string result = http.getString().c_str(); - std::string key = doc[key_s] | ""; + std::string result = http.getString().c_str(); + std::string key = doc[key_s] | ""; + JsonDocument keys_doc; // JsonDocument to hold "keys" after doc is parsed with HTTP body + if (doc[keys_s].is()) { + keys_doc.set(doc[keys_s].as()); + } + JsonArray keys = keys_doc.as(); - doc.clear(); - if (key.length() && DeserializationError::Ok == deserializeJson(doc, result)) { - result = doc[key.c_str()].as(); + if (key.length() || !keys.isNull()) { + doc.clear(); + if (DeserializationError::Ok == deserializeJson(doc, result)) { + if (key.length()) { + result = doc[key.c_str()].as(); + } else { + JsonVariant json = doc.as(); + for (JsonVariant keys_key : keys) { + if (keys_key.is() && json.is()) { + json = json[keys_key.as()].as(); + } else if (keys_key.is() && json.is()) { + json = json[keys_key.as()].as(); + } else { + break; // type mismatch + } + } + result = json.as(); + } + } } expr_new.replace(f, e - f, result.c_str()); }