JSON/XML Data Transformer #204
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
JSON/XML Data Transformer
This Pull Request introduces a custom Flow Designer Action named JSON/XML Data Transformer. This utility is designed to standardize the extraction of single data points from complex, unstructured JSON or XML payloads (typically from REST or SOAP API responses) into a reusable and fail-safe Flow variable. It is built to be resilient within strict Scoped Application environments.
This action solves the critical integration challenge of robustly handling external API response bodies without relying on complex, repeated Script Steps.
nullor missing, by returning a customizableDefault Valueinstead.Primary Use Case: Directly follows a REST or SOAP step in Flow Designer to safely extract a status code, an ID, or a specific error message from the response body.
Action Dynamics and Usage
This action is dynamic because both the raw data and the extraction path are provided as string inputs (data pills), allowing the path to be constructed dynamically if needed.
(JSON/ XML)
user.idor/root/user/@id).extraction_pathfails to find data.Action Outputs
default_value.Trueif a value was found at the path,Falseotherwise.Logic Implementation Details
The Action contains a single Script Step named
Parse and Traverse Datathat uses format-specific logic, specifically engineered to be resilient within the constraints of Scoped Application Flow Designer Script Steps.JSON Logic (Dot Notation / Array Indexing)
global.JSON.parse().(user.name)and supports array indexing(items[1]).default_valueis returned, andsuccessis set toFalse.XML Logic (XPath)
XMLDocument2()combined with the.parseXML()method.XMLDocument), confirming scope compatibility on this instance.xmlDoc.getNodeText(xpath). This returns the text content of the first node matching the provided XPath (e.g.,/root/status).xmlDoc.getNodeText()returnsnull(meaning the path was not found), it explicitly returns thedefault_valueand setssuccesstoFalse.Error Handling
The generic
catchblock employs the resilient methode.toString()to capture any error object including difficult-to-read, restricted Java Exception objects often thrown in Scoped Apps. This ensures a clean, readable error message is always captured in theerror_messageoutput, rather than triggering a secondary security exception or returning an unreadable object.Detailed Test Cases for Validation
These tests confirm successful extraction, proper use of the default value, and robust error handling for malformed inputs in a Scoped Application environment.
JSON Test Cases (Format:
json)The
extraction_pathuses Dot Notation and Array Indexing (e.g.,user.location.city,items[1])Data String
(Input)
Value
Message
{"status": "Ready"}"Ready"True{"user": {"profile": {"email": "[email protected]"}}}user.profile.email"[email protected]"True{"items": ["Alpha", "Beta", "Gamma"]}items[1]"Beta"True{"data": 1}missing.path"UNKNOWN""UNKNOWN"FalseJSON path "missing.path" not found. Returning default value.{"data": 1,data"ERROR""ERROR"FalseFATAL PARSING ERROR (json): SyntaxError: Unexpected end of input (or similar)XML Test Cases (Format:
xml)The
extraction_pathuses strict XPath syntax (e.g.,/root/nodeor//node[1]).(Input)
(XPath)
Value
Message
<resp><id>101</id></resp>/resp/id"101"True<cfg><db><host>srv1</host></db></cfg>/cfg/db/host"srv1"True<list><item>X</item></list>//item"X"True<config><data>1</data></config>/config/tag"NONE""NONE"False"/config/tag"not found. Returning default value.//any"ERROR""ERROR"False