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
| Input | Type | Description | Default |
|---|---|---|---|
| Value | Data | The value to encode into a JSON string. Accepts any data type, including dictionaries, lists, numbers, booleans, and text. | - |
Outputs
| Output | Type | Description |
|---|---|---|
| Json | Data | The 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.
- Add a Dictionary node and give it some keys, for example
nameandemail. - Connect the Dictionary node's Output to the Encode JSON node's Value input.
- 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"}
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.