Core nodes collection for Node-RED runtime providing fundamental building blocks for visual programming flows
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Parser nodes provide data format conversion utilities for working with JSON, XML, CSV, HTML, and YAML formats. These nodes enable seamless transformation between different data representations commonly used in APIs, configuration files, and data exchange.
Parse JSON strings to objects and stringify objects to JSON with formatting options.
/**
* JSON node for JSON parsing and stringification
* Registers as node type: "json"
*/
function JSONNode(config) {
RED.nodes.createNode(this, config);
// Configuration properties:
// config.property - Property to convert (default: "payload")
// config.action - Action: "obj" (to object), "str" (to string), "" (auto-detect)
// config.pretty - Pretty print JSON strings
}Usage Examples:
// Parse JSON string to object
{
"property": "payload",
"action": "obj"
}
// Convert object to pretty JSON string
{
"property": "payload",
"action": "str",
"pretty": true
}
// Auto-detect conversion direction
{
"property": "payload",
"action": ""
}
// Example message transformations:
// Input: { payload: '{"name":"John","age":30}' }
// Output: { payload: { name: "John", age: 30 } }
// Input: { payload: { name: "John", age: 30 } }
// Output: { payload: '{"name":"John","age":30}' }Parse XML strings to JavaScript objects and convert objects back to XML format.
/**
* XML node for XML parsing and generation
* Registers as node type: "xml"
*/
function XMLNode(config) {
RED.nodes.createNode(this, config);
// Configuration properties:
// config.property - Property to convert (default: "payload")
// config.attr - Attribute prefix (default: "$")
// config.chr - Text content key (default: "_")
// config.action - Action: "obj" (to object), "str" (to string), "" (auto-detect)
}Usage Examples:
// Parse XML to object with custom attribute prefix
{
"property": "payload",
"action": "obj",
"attr": "@",
"chr": "#text"
}
// Convert object to XML string
{
"property": "payload",
"action": "str"
}
// Example transformations:
// Input: { payload: '<user id="123"><name>John</name><age>30</age></user>' }
// Output: { payload: { user: { $: { id: "123" }, name: ["John"], age: ["30"] } } }
// Input: { payload: { user: { name: "John", age: 30 } } }
// Output: { payload: '<user><name>John</name><age>30</age></user>' }Parse CSV strings to arrays/objects and convert arrays back to CSV format with configurable delimiters and headers.
/**
* CSV node for CSV parsing and generation
* Registers as node type: "csv"
*/
function CSVNode(config) {
RED.nodes.createNode(this, config);
// Configuration properties:
// config.property - Property to convert (default: "payload")
// config.sep - Field separator (default: ",")
// config.quo - Quote character (default: '"')
// config.esc - Escape character
// config.ret - Return format: "\\n" (newline), "\\r" (carriage return), etc.
// config.temp - Column template/headers
// config.skip - Lines to skip at start
// config.hdrin - Include headers in input
// config.hdrout - Include headers in output
// config.multi - Multi-line mode
// config.unescape - Unescape characters
}Usage Examples:
// Parse CSV with headers to objects
{
"property": "payload",
"sep": ",",
"quo": '"',
"hdrin": true,
"temp": "name,age,email",
"ret": "\\n"
}
// Convert array to CSV with custom separator
{
"property": "payload",
"sep": ";",
"hdrout": true,
"temp": "Name,Age,Email"
}
// Example transformations:
// Input: { payload: "name,age\\nJohn,30\\nJane,25" }
// Output: { payload: [{name:"John",age:"30"},{name:"Jane",age:"25"}] }
// Input: { payload: [{name:"John",age:30},{name:"Jane",age:25}] }
// Output: { payload: "name,age\\nJohn,30\\nJane,25" }Extract data from HTML using CSS selectors, similar to jQuery selection.
/**
* HTML node for HTML parsing with CSS selectors
* Registers as node type: "html"
*/
function HTMLNode(config) {
RED.nodes.createNode(this, config);
// Configuration properties:
// config.property - Property containing HTML (default: "payload")
// config.outproperty - Output property (default: "payload")
// config.tag - CSS selector
// config.ret - Return type: "html", "text", "attr"
// config.as - Return as: "single", "multi"
}Usage Examples:
// Extract text from all paragraphs
{
"property": "payload",
"tag": "p",
"ret": "text",
"as": "multi"
}
// Extract href attributes from links
{
"property": "payload",
"tag": "a",
"ret": "attr",
"as": "multi"
}
// Extract single element HTML
{
"property": "payload",
"tag": "#content .title",
"ret": "html",
"as": "single"
}
// Example transformations:
// Input: { payload: '<div><p>Hello</p><p>World</p></div>' }
// Selector: "p", ret: "text", as: "multi"
// Output: { payload: ["Hello", "World"] }
// Input: { payload: '<a href="/home">Home</a><a href="/about">About</a>' }
// Selector: "a", ret: "attr", as: "multi"
// Output: { payload: ["/home", "/about"] }Parse YAML strings to JavaScript objects and convert objects to YAML format.
/**
* YAML node for YAML parsing and generation
* Registers as node type: "yaml"
*/
function YAMLNode(config) {
RED.nodes.createNode(this, config);
// Configuration properties:
// config.property - Property to convert (default: "payload")
}Usage Examples:
// Parse YAML to object (auto-detect)
{
"property": "payload"
}
// Example transformations:
// Input: { payload: 'name: John\\nage: 30\\nhobbies:\\n - reading\\n - coding' }
// Output: { payload: { name: "John", age: 30, hobbies: ["reading", "coding"] } }
// Input: { payload: { name: "John", age: 30, active: true } }
// Output: { payload: 'name: John\\nage: 30\\nactive: true\\n' }All parser nodes follow similar message processing patterns:
// Standard parser node input handler
this.on("input", function(msg, send, done) {
try {
var property = RED.util.getMessageProperty(msg, config.property || "payload");
var result;
// Determine conversion direction (auto-detect or configured)
if (shouldParseToObject(property, config)) {
result = parseToObject(property);
} else {
result = convertToString(property);
}
// Set result back to message
RED.util.setMessageProperty(msg, config.outproperty || config.property || "payload", result);
send(msg);
done();
} catch (error) {
done(error);
}
});Parser nodes handle various error conditions:
// Common error scenarios handled by parser nodes:
// Invalid JSON
// Input: { payload: '{"invalid": json}' }
// Result: Error message sent to catch nodes
// Invalid XML
// Input: { payload: '<unclosed><tag>' }
// Result: Error with parsing details
// CSV parsing errors
// Input: { payload: 'unclosed,"quote' }
// Result: Error indicating malformed CSV
// HTML selector errors
// Input: Invalid CSS selector syntax
// Result: Error with selector details
// YAML parsing errors
// Input: { payload: 'invalid: yaml: structure:' }
// Result: Error with line/column information// Complex CSV configuration
{
"sep": ",", // Field separator
"quo": '"', // Quote character
"esc": "\\", // Escape character
"ret": "\\n", // Line ending
"skip": 2, // Skip first 2 lines
"hdrin": true, // First line contains headers
"hdrout": true, // Include headers in output
"multi": true, // Handle multi-line fields
"unescape": true, // Unescape characters
"temp": "Name,Age,City" // Column template
}// Custom XML parsing configuration
{
"attr": "@", // Attribute prefix
"chr": "#text", // Text content key
"action": "obj" // Force conversion direction
}// Advanced CSS selectors
{
"tag": "table tr:nth-child(2n) td.price", // Even table rows, price cells
"ret": "text"
}
{
"tag": "div[data-type='product'] .title", // Products with title class
"ret": "html"
}
{
"tag": "img", // All images
"ret": "attr", // Get src attributes
"as": "multi"
}Parser nodes handle various data type conversions automatically:
// Automatic type detection and conversion
interface TypeConversion {
// String to Object parsing
jsonString: string → object;
xmlString: string → object;
csvString: string → Array<object>;
yamlString: string → object;
// Object to String generation
object → jsonString: string;
object → xmlString: string;
Array<object> → csvString: string;
object → yamlString: string;
// HTML extraction
htmlString + selector → Array<string> | string;
}