Skip to content

Commit 1ae2332

Browse files
author
drowl87
committed
enhance DynamicNode to handle JSON input more robustly and update version to 0.1.5
1 parent 252318c commit 1ae2332

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

nodes/DynamicNode/DynamicNode.node.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,25 @@ export class DynamicNode implements INodeType {
3636
// 1) Pull in the incoming items
3737
const items = this.getInputData();
3838

39-
// 2) Get the user-provided node JSON
40-
const raw = this.getNodeParameter('nodeJson', 0) as any;
41-
if (typeof raw !== 'object') {
39+
// 2) Get the user-provided node JSON (string or object)
40+
const rawParam = this.getNodeParameter('nodeJson', 0) as any;
41+
// Accept either a true JSON object or a JSON string
42+
let raw: any;
43+
if (typeof rawParam === 'string') {
44+
try {
45+
raw = JSON.parse(rawParam);
46+
} catch {
47+
throw new NodeOperationError(
48+
this.getNode(),
49+
'Node JSON must be a valid JSON object or a parseable JSON string',
50+
);
51+
}
52+
} else {
53+
raw = rawParam;
54+
}
55+
if (typeof raw !== 'object' || raw === null) {
56+
throw new NodeOperationError(this.getNode(), 'Node JSON must be an object');
57+
} {
4258
throw new NodeOperationError(this.getNode(), 'Node JSON must be an object');
4359
}
4460

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "n8n-nodes-dynamic-node",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "A dynamic n8n node wrapper that can execute any node JSON by feeding it at runtime.",
55
"keywords": [
66
"n8n-community-node-package",

0 commit comments

Comments
 (0)