0CodeKit icon

0CodeKit

A toolbox of no-code utilities

Operator → Advanced Switch

AI-generated

Overview

The Operator: Advanced Switch operation in this custom n8n node allows you to perform advanced conditional logic (switching) based on keys and JSON data. It can either fetch the JSON from an external URL or use a stringified JSON provided directly in the node. This is useful for dynamic routing, decision-making, or branching workflows based on complex conditions defined in JSON.

Common scenarios:

  • Routing workflow execution based on values found in a JSON object.
  • Dynamically switching between different branches depending on external configuration.
  • Centralizing switch logic in a JSON file for easier maintenance.

Practical example:
Suppose you have a set of rules stored in a JSON file (either locally or at a remote URL). You want your workflow to check several keys and take actions based on their values. This node lets you specify which keys to check and where to get the JSON, then outputs the result for further processing.


Properties

Name Meaning
External JSON? Determines whether to load the JSON from an external URL (true) or use the provided stringified JSON content (false).
Url The URL to fetch the JSON from. Only shown if "External JSON?" is true.
Content Stringified JSON data to use for switching. Only shown if "External JSON?" is false. Must be valid JSON.
Keys List of keys (one per line) to check within the JSON. These are used as the basis for the switch/decision logic.

Output

  • The output is a JSON object (or array of objects) containing the results of the advanced switch operation.
  • The structure will reflect the evaluation of the specified keys against the provided or fetched JSON.
  • If an error occurs (and "Continue On Fail" is enabled), the output will include an error field with the error message.

Example output:

[
  {
    "result": "value based on key(s)",
    // ...other fields depending on the switch logic and input JSON
  }
]

Dependencies

  • External Service: If "External JSON?" is enabled, the node requires access to the specified URL to fetch the JSON.
  • API Key: The node requires a credential named codeKitApi to function.
  • n8n Configuration: Ensure that network access is available for any external URLs used.

Troubleshooting

Common issues:

  • Invalid JSON: If the "Content" property contains malformed JSON, the node will throw a parsing error.
  • Network errors: If fetching from a URL fails (e.g., due to connectivity issues or invalid URL), an error will occur.
  • Missing keys: If the specified keys do not exist in the JSON, the output may not contain expected results.

Error messages and resolutions:

  • "Unexpected token ... in JSON": Check that your "Content" is valid, stringified JSON.
  • "Request failed with status code ...": Verify the URL is correct and accessible.
  • "Cannot read property ... of undefined": Ensure the keys you specify actually exist in the JSON structure.

Links and References

Discussion