Skip to main content

Switch@1

Node Switch@1 allows to execute different sub transformation pipelines based on a switch statement with multiple cases.

The node evaluates a value at a specified path and executes the transformations of the first matching case. If no case matches, optional default transformations are executed.

Adapter Prerequisites​

  • General availability: All adapters support this node type.

Node Configuration​

For fields path, see Overview.

triggers:
- type: FromExecutePipelineCommand@1
transformations:
- type: SetPrimitiveValue@1
targetPath: $.customer.type
value: standard
- type: Switch@1
path: $.customer.type # Path to the value to evaluate
valueType: String # Data type of the value (String, Int, Boolean, Double, DateTime, Enum)
cases: # List of cases to evaluate
- value: "premium" # Value to match against
transformations: # Sub pipeline executed if this case matches
- type: Simulation@1
simulations:
- targetPath: $.customer.discount
simulatorKey: Math.DoubleRandom
configuration: "{min: 0.15, max: 0.25}"
- value: "standard"
transformations:
- type: Simulation@1
simulations:
- targetPath: $.customer.discount
simulatorKey: Math.DoubleRandom
configuration: "{min: 0.05, max: 0.10}"
- value: "basic"
transformations:
- type: SetPrimitiveValue@1
targetPath: $.customer.discount
value: 0.02
valueType: Double
default: # Optional: executed if no case matches
- type: SetPrimitiveValue@1
targetPath: $.customer.discount
value: 0.0
valueType: Double

Configuration Properties​

PropertyTypeRequiredDescription
pathstringYesJSONPath to the value that should be evaluated
valueTypestringYesData type for comparison (String, Int, Boolean, Double, DateTime, Enum)
casesarrayYesList of case objects, each containing value and transformations
cases[].valueanyYesValue to match against (type must match valueType)
cases[].transformationsarrayYesSub pipeline to execute if this case matches
defaultarrayNoOptional sub pipeline to execute if no case matches

Behavior​

  • Cases are evaluated in order, and the first matching case is executed (similar to C# switch statement)
  • Only one case is executed, even if multiple cases would match
  • If no case matches and default is defined, the default transformations are executed
  • If no case matches and no default is defined, no transformations are executed
  • Value comparison uses strict equality (.Equals() method)

Supported Value Types​

  • String: Text comparison (case-sensitive)
  • Int: 32-bit integer comparison
  • Boolean: Boolean comparison (true/false)
  • Double: Floating-point number comparison
  • DateTime: Date and time comparison
  • Enum: Integer-based enum comparison

Example Use Cases​

Customer Type Processing​

- type: Switch@1
path: $.customer.type
valueType: String
cases:
- value: "enterprise"
transformations:
- type: SetPrimitiveValue@1
targetPath: $.pricing.plan
value: "enterprise"
- value: "business"
transformations:
- type: SetPrimitiveValue@1
targetPath: $.pricing.plan
value: "business"
defaultTransformations:
- type: SetPrimitiveValue@1
targetPath: $.pricing.plan
value: "standard"

Status Code Processing​

- type: Switch@1
path: $.response.statusCode
valueType: Int
cases:
- value: 200
transformations:
- type: SetPrimitiveValue@1
targetPath: $.status
value: "success"
- value: 404
transformations:
- type: SetPrimitiveValue@1
targetPath: $.status
value: "not_found"
- value: 500
transformations:
- type: SetPrimitiveValue@1
targetPath: $.status
value: "server_error"
defaultTransformations:
- type: SetPrimitiveValue@1
targetPath: $.status
value: "unknown"