Login to follow
KeyValueTransformer

KeyValueTransformer (ODC)

Stable version 1.0.0 (Compatible with ODC)
Uploaded on 02 December 2025 by Sudip Pal
KeyValueTransformer

KeyValueTransformer (ODC)

Documentation
1.0.0

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:

  1. Pass a JSON string to the input parameter JSONText.

  2. The code parses the JSON string into a JavaScript object.

  3. 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]).

  4. Any string that looks like Base64 (long enough and matching the Base64 pattern) is marked as binary (IsBinary: true).

  5. 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: false
Key: person.photo, Value: iVBORw0KGgoAAAANSUhEUgAAA..., IsBinary: true
Key: tags[0], Value: js, IsBinary: false
Key: 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