json-extractor

n8n node for extracting and parsing JSON from text

Package Information

Released: 6/26/2025
Downloads: 2 weekly / 14 monthly
Latest Version: 0.1.0
Author: Your Name

Documentation

N8N JSON Extractor Node

A custom n8n node for extracting and parsing JSON data from text content. This node is particularly useful when working with API responses, log files, or any text that contains embedded JSON data.

Features

  • Multiple extraction modes: Extract JSON using different strategies
  • Flexible parsing: Handle various JSON formats and structures
  • Error handling: Graceful handling of malformed JSON with optional continuation
  • Easy integration: Simple installation and configuration

Installation

Via npm (Recommended)

npm install n8n-nodes-json-extractor

Manual Installation

  1. Clone this repository
  2. Install dependencies: npm install
  3. Build the node: npm run build
  4. Link to your n8n installation: npm link

Usage

After installation, the JSON Extractor node will be available in your n8n workflow editor under the "Transform" category.

Node Configuration

The node provides the following configuration options:

Input Text

  • Type: String (multiline)
  • Required: Yes
  • Description: The text content from which to extract JSON data

Extract Mode

Choose how the JSON should be extracted from the input text:

  1. Outer Curly Braces (default)

    • Extracts JSON between the outermost { and } braces
    • Ideal for text with JSON embedded within other content
    • Example: "Some text {\"key\": \"value\"} more text"{\"key\": \"value\"}
  2. Full Text

    • Treats the entire input as JSON
    • Use when your input is pure JSON
    • Example: {\"key\": \"value\"}{\"key\": \"value\"}
  3. Regular Expression

    • Uses a custom regex pattern to extract JSON
    • Provides maximum flexibility for complex extraction scenarios
    • Requires a valid regex pattern in the "Regular Expression" field

Regular Expression

  • Type: String
  • Visible: Only when "Extract Mode" is set to "Regular Expression"
  • Default: \\{[^]*\\}
  • Description: Custom regex pattern for JSON extraction

Output

The node outputs an object containing:

  • extracted: The raw extracted JSON string
  • parsed: The parsed JSON object
  • All properties from the parsed JSON are also available at the root level

Example Output

Input text: "API Response: {\"status\": \"success\", \"data\": {\"id\": 123}}"

Output:

{
  "extracted": "{\"status\": \"success\", \"data\": {\"id\": 123}}",
  "parsed": {
    "status": "success",
    "data": {
      "id": 123
    }
  },
  "status": "success",
  "data": {
    "id": 123
  }
}

Use Cases

  • API Response Processing: Extract JSON from HTTP response bodies that contain additional text
  • Log File Analysis: Parse JSON logs embedded in text files
  • Data Transformation: Convert text-based data sources containing JSON
  • Web Scraping: Extract JSON data from HTML pages or JavaScript variables
  • Configuration Parsing: Extract JSON configuration from mixed-format files

Error Handling

The node includes robust error handling:

  • Invalid JSON: Clear error messages when JSON parsing fails
  • No Match Found: Informative errors when extraction patterns don't match
  • Continue on Fail: Option to continue workflow execution even when errors occur

Development

Building

npm run build

Watching for Changes

npm run build:watch

Formatting

npm run format

Contributing

Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.

License

MIT

Support

If you encounter any issues or have questions, please create an issue in the GitHub repository.

Discussion