Skip to content

JSON: To String

Converts any input data into a JSON-formatted string. Supports pretty-printing with indentation for readability or compact output for efficient storage/transmission. Handles diverse data types and ensures a consistent JSON representation.
Preview

Usage

Use this node when you need to serialize data (objects, arrays, numbers, booleans, etc.) into a JSON string for logging, storage, configuration export, or passing into downstream nodes that expect a string payload (e.g., HTTP requests, file writers, or prompt builders). Typically placed after data assembly/transformation nodes and before output or transport nodes.

Inputs

FieldRequiredTypeDescriptionExample
inputTrueWILDCARDThe data to convert to a JSON string. Accepts objects/dicts, arrays/lists, strings, numbers, booleans, null, or other values.{'user': {'id': 123, 'name': 'Ada'}, 'active': True, 'roles': ['admin', 'editor']}
prettyTrueBOOLEANIf true, formats the JSON with indentation for readability. If false, outputs a compact JSON string without extra spaces.True

Outputs

FieldTypeDescriptionExample
json_stringSTRINGThe JSON-formatted string representation of the input.{ "user": { "id": 123, "name": "Ada" }, "active": true, "roles": [ "admin", "editor" ] }

Important Notes

  • Strings are quoted: If the input is already a string, the output will be a JSON string (quoted and escaped). This is correct JSON behavior.
  • Pretty vs compact: Setting pretty to false produces compact output without spaces, suitable for storage or network transfer.
  • Unicode preserved: Non-ASCII characters are preserved (not escaped) in the output.
  • Type handling: Numbers and booleans are emitted as standard JSON literals (e.g., true/false). Null becomes null.
  • Fallback for complex objects: If an input value cannot be natively serialized to JSON, it is converted to its string representation.
  • Wildcard input: The node accepts any data type; ensure the resulting JSON structure matches downstream expectations.

Troubleshooting

  • Output shows extra quotes around my text: You likely passed a plain string as input. JSON strings are quoted by design. If you need raw text, skip JSON serialization or remove quotes downstream.
  • Output is a single-line, compact string: Set pretty to true to enable indentation and line breaks for readability.
  • Downstream node rejects the payload: Confirm the consumer expects a JSON string and that the structure matches its schema. If you intended structured data (not a string), use a node that outputs objects instead.
  • Unexpected values for custom objects: Complex or unsupported objects are stringified. Convert them to dictionaries/lists first or extract the required fields before serialization.
  • Non-English characters appear garbled: The node preserves Unicode. If you see garbling, check the display font/encoding of the viewer or the downstream system, not this node.