Skip to main content

Encode JSON

Uncontrolled node

Overview

Encode JSON converts a value — such as a dictionary, list, number, boolean, or text — into a JSON formatted string. This is useful whenever you need to serialize structured data, for example to send it as the body of an API request, store it as text, or pass it to a system that expects JSON.

Because Encode JSON is an uncontrolled node, it has no run event. The workflow evaluates it on demand when another node reads its Json output.

Error handling

If the value cannot be encoded as JSON (for example, an object containing a circular reference), the node does not fail the workflow. Instead, the Json output is set to an error object:

{ "error": "Encode JSON: value could not be encoded as JSON" }

You can check for this shape downstream to handle encoding failures gracefully.

Inputs

InputTypeDescriptionDefault
ValueDataThe value to encode into a JSON string. Accepts any data type, including dictionaries, lists, numbers, booleans, and text.-

Outputs

OutputTypeDescription
JsonDataThe JSON string representation of the input value. If encoding fails, contains an { error } object instead.

This node emits no events.

Example

A common use case is building a structured payload and sending it to an external service as a JSON string.

  1. Add a Dictionary node and give it some keys, for example name and email.
  2. Connect the Dictionary node's Output to the Encode JSON node's Value input.
  3. Connect the Encode JSON node's Json output to the body input of an HTTP request node, or to a text display to preview the result.

Given a dictionary like:

{ "name": "Ada", "email": "ada@example.com" }

The Json output will be the string:

{"name":"Ada","email":"ada@example.com"}
Round-tripping data

Use the Decode JSON node to convert a JSON string back into an object, array, or value. Encode JSON and Decode JSON pair well together when you need to move structured data through text-based systems.