Skip to content

[Rules] Add string functions unescape, escape, parse and json - #5600

Open
tonhuisman wants to merge 4 commits into
letscontrolit:megafrom
tonhuisman:feature/Rules-add-unescape-escape-parse-json-functions
Open

[Rules] Add string functions unescape, escape, parse and json#5600
tonhuisman wants to merge 4 commits into
letscontrolit:megafrom
tonhuisman:feature/Rules-add-unescape-escape-parse-json-functions

Conversation

@tonhuisman

@tonhuisman tonhuisman commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Inspired by #5597 and some Forum requests here and here, and the long-standing TODO for proper JSON parsing.

Features:

  • String function {unescape:<string-to-unescape>} (remove \ escape-prefixes from % [ ] { } ( ) and :).
  • String function {escape:<string-to-escape>} (insert the \ prefix to % [ ] { } ( ) and :).
  • String function {parse:<param>:[<separator>]:<string-to-parse-from>} fetch the 1-based parameter from the string, using the separator (default when empty: ,).
  • String function {json:<json-path>:[<asJson>]:<json-string>} retrieve a value from a JSON (escaped) string, using the often used name.sub.array[n].attr notation. Returns numeric, string, bool, array(as csv) and object(as name,value csv) values. When asJson is 1, returns a JSON-compatible value (quoted strings, bool: true/false, []-wrapped arrays and {}-wrapped objects.
  • The extracted JSON parser is based on the code from HTTPResonseParser.cpp, adding support for bool and object values, and also nesting (recursive). Has a feature-flag FEATURE_JSON__PARSER that auto-enables if P037 or the HTTP_RESPONSE_PARSER are included.
  • [HTTPResponseParser] Use the extended JSON parser.
  • [P037] Use the extended JSON parser instead of just the simple name.attr parser it had.
  • [Docs] Added for the new string functions.
  • [EasyCode] Keywords added.

NB: These features are only available in ESP32 builds, as it won't fit in the current set of ESP8266 builds (see our policy here). It can be enabled for a Custom build, using the feature flags FEATURE_EXTENDED_STRING_FUNCTIONS and FEATURE_JSON_PARSE (enable both to get the JSON-parse feature).

TODO:

  • Testing
  • Extend docs where needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant