Convert String to JSON

Action ID: string_to_json

Description

Convert a string representation to a JSON object. This node parses JSON-formatted strings and returns the structured data.

Input Parameters

Name
Type
Required
Default
Description

string_to_convert

string

-

The string to convert to JSON.

View JSON Schema
{
  "description": "Convert string to json node input.",
  "properties": {
    "string_to_convert": {
      "title": "String to Convert",
      "type": "string",
      "description": "The string to convert to JSON."
    }
  },
  "required": [
    "string_to_convert"
  ],
  "title": "StringToJsonNodeInput",
  "type": "object"
}

Output Parameters

Name
Type
Description

json_output

object or array

The JSON output from the string

View JSON Schema
{
  "description": "Convert string to json node output.",
  "properties": {
    "json_output": {
      "title": "JSON Output",
      "description": "The JSON output from the string."
    }
  },
  "required": [
    "json_output"
  ],
  "title": "StringToJsonNodeOutput",
  "type": "object"
}

How It Works

This node takes a string representation of JSON and parses it into a JavaScript object or array. The parser validates the JSON format and throws an error if the string is invalid. Once parsed, the JSON data is available as a structured object that can be manipulated by other nodes in your workflow.

Usage Examples

Example 1: Parse JSON Object

Input:

string_to_convert: "{\"name\": \"John Doe\", \"age\": 30, \"email\": \"[email protected]\"}"

Output:

json_output: {
  "name": "John Doe",
  "age": 30,
  "email": "[email protected]"
}

Example 2: Parse JSON Array

Input:

string_to_convert: "[{\"id\": 1, \"name\": \"Item A\"}, {\"id\": 2, \"name\": \"Item B\"}]"

Output:

json_output: [
  {"id": 1, "name": "Item A"},
  {"id": 2, "name": "Item B"}
]

Example 3: Parse Nested JSON

Input:

string_to_convert: "{\"user\": {\"profile\": {\"first_name\": \"John\", \"last_name\": \"Doe\"}}, \"status\": \"active\"}"

Output:

json_output: {
  "user": {
    "profile": {
      "first_name": "John",
      "last_name": "Doe"
    }
  },
  "status": "active"
}

Common Use Cases

  • API Response Parsing: Convert JSON strings from API responses into structured objects

  • File Content Processing: Parse JSON strings read from text files or databases

  • String Conversion: Convert stringified data from workflows or external systems to JSON objects

  • Data Transformation: Prepare data for subsequent processing nodes that expect JSON objects

  • Webhook Payload Parsing: Parse JSON payloads received from webhooks into structured data

  • Legacy System Integration: Convert string-based data from older systems into modern JSON format

Error Handling

Error Type
Cause
Solution

Invalid JSON

Input string contains malformed JSON

Check syntax: missing quotes, brackets, or commas

Unexpected Token

JSON contains characters in wrong position

Validate JSON structure using a JSON validator tool

Unterminated String

String value missing closing quote

Add missing closing quote to all string values

Invalid Escape

Invalid escape sequence in string (e.g., \x)

Use valid escapes like \\, \", \n, \t

Unexpected End

JSON string ends prematurely

Ensure all opening brackets and braces are closed

Duplicate Keys

Same key defined twice in object

Remove or rename duplicate object keys

Notes

  • Valid JSON: The input string must be valid JSON format. Invalid JSON will result in an error.

  • Object or Array: The output can be either a JSON object or an array, depending on the input string.

  • Data Type Preservation: JSON data types (string, number, boolean, null, array, object) are preserved during conversion.

  • Common Use Case: Use this node when you receive JSON as a string from APIs or other sources and need to parse it for further processing.

  • No Modification: This node only parses the JSON; it doesn't modify or transform the data structure.

Last updated

Was this helpful?