Actions20
- Assistant Actions
- Embedding Actions
- File Actions
- Report Actions
- Text Actions
- Thread Actions
Overview
This node provides functionality to parse a JSON string into a JavaScript object with enhanced error handling. Specifically, it supports an operation to parse JSON text input and optionally uses an OpenAI language model to automatically fix JSON syntax errors before parsing. This is useful in scenarios where the JSON input might be malformed or incomplete, and you want to leverage AI assistance to correct common mistakes and still obtain a valid parsed object.
Practical examples include:
- Parsing user-generated JSON data that may contain syntax errors.
- Automatically correcting and parsing JSON output from other systems or APIs that sometimes produce invalid JSON.
- Using AI to assist in recovering data from corrupted JSON strings.
Properties
Name | Meaning |
---|---|
Authentication | Choose which API credentials to use: - OpenAI Analytics API - OpenAI API |
JSON Input | The JSON string to parse into a JavaScript object. |
Use AI Fix | Whether to use OpenAI to fix JSON syntax errors before parsing. |
OpenAI Model | The OpenAI model to use for fixing JSON syntax errors (only shown if "Use AI Fix" is enabled). |
Output
The node outputs the parsed JSON as a JavaScript object in the json
field of the output item. If the input JSON is invalid and AI fixing is disabled or fails, the node will throw an error or return an error message depending on the error handling settings.
No binary data output is produced by this operation.
Dependencies
- Requires an API key credential for OpenAI services, either via dedicated OpenAI Analytics API credentials or standard OpenAI API credentials.
- Uses OpenAI models to optionally fix JSON syntax errors.
- Requires network access to OpenAI endpoints.
Troubleshooting
Common issues:
- Invalid JSON input without AI fix enabled will cause parsing errors.
- Network or authentication errors when calling OpenAI API.
- Specifying an unsupported or unavailable OpenAI model for fixing JSON.
Error messages and resolutions:
"Unsupported resource"
: Ensure the resource parameter is set to "text".- JSON parsing errors: Enable "Use AI Fix" to allow automatic correction or verify the JSON input format.
- Credential loading errors: Verify that the API key credentials are correctly configured in n8n.
- OpenAI API errors: Check API key validity, usage limits, and network connectivity.