Flatten JSONText to Key-Value List in ODC Client Action
Purpose:This JavaScript code is used in an ODC Client Action JS logic to flatten a nested JSON string into a list of key-value pairs, while detecting Base64-encoded binary values. The output is assigned to an OutSystems parameter (KeyValueList) for further use.
How it works:
Pass a JSON string to the input parameter JSONText.
The code parses the JSON string into a JavaScript object.
It recursively flattens all nested objects and arrays: nested objects use dot notation for keys (e.g., person.name), and arrays use [index] notation (e.g., tags[0]).
Any string that looks like Base64 (long enough and matching the Base64 pattern) is marked as binary (IsBinary: true).
The final result is a flat array of key-value objects assigned to KeyValueList.
Input Parameter:
JSONText (Text): JSON string to flatten
Output Parameter:
KeyValueList (List of records): Each record has:
Key (Text) → Flattened key path
Value (Text) → Value from JSON
IsBinary (Boolean, optional) → True if the value is detected as Base64
Example:
Input JSON (JSONText):{"person": {"name": "John","photo": "iVBORw0KGgoAAAANSUhEUgAAA..."},"tags": ["js", "outsystems"]}
Output (KeyValueList):Key: person.name, Value: John, IsBinary: falseKey: person.photo, Value: iVBORw0KGgoAAAANSUhEUgAAA..., IsBinary: trueKey: tags[0], Value: js, IsBinary: falseKey: tags[1], Value: outsystems, IsBinary: false
Key Features:
Flattens nested JSON objects and arrays
Detects Base64 strings as binary
Produces a flat key-value list suitable for use in ODC Client Actions