0CodeKit icon

0CodeKit

A toolbox of no-code utilities

Actions108

Overview

The "Advanced Switch" operation within the "Operator" resource of this node provides a flexible way to perform conditional logic based on JSON data. It allows users to evaluate one or multiple keys against a given JSON object and route or process data accordingly. This operation supports both internal JSON content (provided as a string) and external JSON fetched from a URL.

Common scenarios where this node is beneficial include:

  • Dynamically branching workflows based on values inside complex JSON objects.
  • Evaluating multiple keys in JSON to decide subsequent processing steps.
  • Integrating with APIs or services that return JSON, then conditionally handling responses.
  • Using variables defined in code for dynamic evaluation.

Practical example:

  • You have a JSON configuration or API response and want to check if certain keys meet specific criteria to trigger different workflow paths.
  • You provide either a JSON string directly or a URL pointing to JSON data, specify keys to check, and the node evaluates these keys to determine the output.

Properties

Name Meaning
Code Variables A collection of named variables defined in the code editor for the selected function. Each variable has a name or ID and an associated value. These can be used dynamically within the code execution context.
External JSON? Boolean flag indicating whether the JSON data should be fetched from an external URL (true) or provided directly as a stringified JSON (false).
Url The URL to fetch JSON data from when External JSON? is set to true.
Content Stringified JSON content to use when External JSON? is set to false. Must be valid JSON formatted as a string.
Keys One or more keys to evaluate within the JSON data. Multiple keys can be specified by placing each key on a new line. These keys are used to perform the switch/conditional logic on the JSON content.

Output

The node outputs a JSON array containing the results of the advanced switch evaluation. The exact structure depends on the evaluated keys and the logic implemented in the backend service it calls. Typically, the output will reflect the matched conditions or the extracted values based on the keys provided.

If binary data were involved, it would be summarized here; however, this operation deals only with JSON data and does not output binary content.

Dependencies

  • Requires an API key credential for authentication with the external service powering the node's operations.
  • The node makes HTTP POST requests to endpoints corresponding to the resource and operation (e.g., operator/advancedswitch).
  • If using external JSON, the node must have network access to fetch the JSON from the specified URL.

Troubleshooting

  • Invalid JSON error: When providing JSON content directly (External JSON? = false), ensure the JSON string is valid and properly stringified. Invalid JSON will cause parsing errors.
  • Network errors: If fetching JSON from a URL (External JSON? = true), verify the URL is accessible and returns valid JSON.
  • Empty or missing keys: Ensure that the keys specified exist in the JSON data; otherwise, the switch may not behave as expected.
  • Incorrect variable names: When using code variables, make sure the variable names match those defined in the code editor exactly.
  • API authentication failures: Confirm that the required API key credential is configured correctly in n8n.

Links and References

Discussion