# 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. |

<details>

<summary>View JSON Schema</summary>

```json
{
  "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"
}
```

</details>

## Output Parameters

| Name         | Type            | Description                     |
| ------------ | --------------- | ------------------------------- |
| json\_output | object or array | The JSON output from the string |

<details>

<summary>View JSON Schema</summary>

```json
{
  "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"
}
```

</details>

## 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\": \"john@example.com\"}"
```

**Output:**

```
json_output: {
  "name": "John Doe",
  "age": 30,
  "email": "john@example.com"
}
```

### 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.agenticflow.ai/reference/nodes/string_to_json.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
