Skip to main content

To JSON Node

To JSON Node Screenshot

Overview

The To JSON Node is used to convert a given input into its JSON equivalent, effectively stringifying the value. This can be useful when you need to serialize an object or array into a string format for further processing or storage.

The node provides an option to format the JSON output with indentation for easier reading.

Inputs

TitleData TypeDescriptionDefault ValueNotes
DataanyThe data to be converted to JSON.(required)

Example 1: Convert an object to JSON

  1. Create an Object Node and set the value to the following:

    {
    "name": "Claude Shannon",
    "occupation": "Computer scientist"
    }
  2. Create a To JSON Node and connect the Object Node to it.

  3. Run the graph. The To JSON Node should output the JSON string representation of the object.

To JSON Node Example 1

Error Handling

The To JSON Node will throw an error if it fails to convert the input to a JSON string. This can happen if the input contains a value that is not serializable, such as a function or a circular reference.

FAQ

Q: Can I use the To JSON Node to convert a string to JSON?

A: Yes, but the output will be a JSON string representation of the original string. If you want to parse a JSON string into an object or array, use the Extract JSON Node or the Extract Object Path Node.

Q: Can I use the To JSON Node to convert a number or boolean to JSON?

A: Yes, the To JSON Node can convert any data type to a JSON string. For numbers and booleans, the output will be the string representation of the original value.

Q: What does the "Indented" setting do?

A: When the "Indented" setting is enabled, the JSON output will be formatted with indentation and line breaks for easier reading. This can be useful when you need to inspect the JSON output for debugging purposes.

See Also