Overview

The To JSON Block converts any input value into its JSON string representation. This is useful for serializing data structures, debugging, or preparing data for storage or transmission in a text format.

Key Features

  • Converts any JavaScript value to a JSON string
  • Preserves data structure and types
  • Handles complex nested objects and arrays
  • Useful for data serialization and debugging

Inputs

input
any
required

The value to convert to JSON. Can be any type including objects, arrays, strings, numbers, booleans, or null.

Outputs

output
string

The JSON string representation of the input value.

Example: Convert an Object to JSON

  1. Create an Object Block with values:
    {
      "name": "John Smith",
      "age": 30,
      "hobbies": ["reading", "hiking"]
    }
    
  2. Add a To JSON Block and connect the Object Block to its input.
  3. Run the flow. The output will be the stringified JSON:
    {"name":"John Smith","age":30,"hobbies":["reading","hiking"]}
    

Error Handling

  • Handles circular references by throwing an error
  • Non-JSON-serializable values (like functions) will be omitted
  • Undefined values will be omitted from objects

FAQ

See Also