🔤String to JSON Node

Overview

The String to JSON node converts a JSON-formatted string into a structured JSON object. This node is useful when you need to parse JSON data that's stored as a string (e.g., from API responses, file contents, or text inputs) into a usable JSON structure for further processing in your workflow.

Node Details

  • Node Type: STRING_TO_JSON

  • Category: Utils

  • Title: Convert String to JSON

  • Description: Convert a string representation to a JSON object

How It Works

The node takes a string containing valid JSON syntax and parses it into a structured JSON object. The parsing is done using Python's built-in json.loads() function, which supports:

  • JSON objects (dictionaries)

  • JSON arrays (lists)

  • Nested structures

  • All JSON data types (strings, numbers, booleans, null)

Input Requirements

The input string must be valid JSON syntax. Common valid formats include:

JSON Object:

{"name": "John", "age": 30, "city": "New York"}

JSON Array:

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

Nested JSON:

{
  "user": {
    "name": "Jane",
    "preferences": {
      "theme": "dark",
      "notifications": true
    }
  }
}

Configuration

Input Parameters

Parameter
Type
Required
Description

string_to_convert

String (Long Text)

Yes

The JSON-formatted string to convert to a JSON object

UI Configuration:

  • Field Type: Long Text Area

  • Display Order: 0

  • Title: "String to Convert"

Output Parameters

Parameter
Type
Description

json_output

JSON Object or Array

The parsed JSON structure. Can be either a dictionary or a list of dictionaries

Usage Examples

Example 1: Converting API Response String

Input:

string_to_convert: '{"status": "success", "data": {"id": 123, "name": "Product A"}}'

Output:

{
  "json_output": {
    "status": "success",
    "data": {
      "id": 123,
      "name": "Product A"
    }
  }
}

Example 2: Converting Array String

Input:

string_to_convert: '[{"id": 1, "value": "First"}, {"id": 2, "value": "Second"}]'

Output:

{
  "json_output": [
    {"id": 1, "value": "First"},
    {"id": 2, "value": "Second"}
  ]
}

Common Use Cases

  1. Parsing API Responses: Convert string responses from HTTP requests into structured data

  2. File Processing: Parse JSON files that were read as text

  3. Data Transformation: Convert JSON strings from database fields into workable objects

  4. Integration: Process JSON data from external systems or webhooks

  5. Configuration Loading: Parse configuration strings into usable settings objects

Error Handling

The node will fail if:

  • The input string is not valid JSON syntax

  • The string contains malformed JSON (missing quotes, brackets, commas, etc.)

  • The string is empty or null

Common JSON Syntax Errors

Invalid (will fail):

{name: "John"}                    // Missing quotes around key
{'name': 'John'}                  // Single quotes not valid JSON
{"name": "John",}                 // Trailing comma
{name: "John", age: undefined}    // Undefined not valid JSON

Valid (will succeed):

{"name": "John"}
{"name": "John", "age": 30}
[1, 2, 3]
{"items": [{"id": 1}]}

Tips and Best Practices

  1. Validate Input: Ensure your input string is valid JSON before passing it to this node

  2. Handle Escaping: Make sure special characters in strings are properly escaped

  3. Test with Sample Data: Test your JSON strings with a JSON validator first

  4. Error Recovery: Add error handling nodes after this node to catch parsing failures

  5. Use with Variables: This node works well with dynamic content from previous nodes

  • JSON to String: Converts JSON objects back to string format

  • HTTP Request: Often produces JSON strings that need parsing

  • File Read: Reads file contents as strings that may need JSON parsing

  • Data Transform: Works with the JSON output for further data manipulation

Technical Details

  • Implementation: Uses Python's json.loads() function

  • Execution Mode: Synchronous (also available as async)

  • Performance: Fast parsing for most JSON sizes

  • Memory: Loads entire JSON structure into memory

Troubleshooting

Issue: Node fails with "Invalid JSON" error

Solution:

  • Verify your string is valid JSON using a JSON validator

  • Check for common syntax errors (quotes, commas, brackets)

  • Ensure no trailing commas in objects or arrays

Issue: Special characters cause parsing errors

Solution:

  • Ensure special characters are properly escaped with backslashes

  • Use double quotes for strings, not single quotes

  • Verify Unicode characters are properly encoded

Issue: Large JSON strings fail to parse

Solution:

  • Check memory limits in your workflow environment

  • Consider breaking down large JSON into smaller chunks

  • Use streaming parsers for very large datasets (requires custom node)

Support

For additional help or to report issues with this node:

  • Check the workflow logs for detailed error messages

  • Validate your JSON using online tools like JSONLint

  • Review the workflow execution history for input/output examples

Last updated

Was this helpful?