mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 14:44:05 -08:00
⚡ Make node "json" data available in expression via "json" key
This commit is contained in:
parent
cad86f6623
commit
b1719f1bcc
|
@ -31,7 +31,7 @@ With the help of expressions, it is possible to set node parameters dynamically
|
||||||
|
|
||||||
An expression could look like this:
|
An expression could look like this:
|
||||||
|
|
||||||
My name is: `{{$node["Webhook"].data["query"]["name"]}}`
|
My name is: `{{$node["Webhook"].json["query"]["name"]}}`
|
||||||
|
|
||||||
This one would return "My name is: " and then attach the value that the node with the name "Webhook" outputs and there select the property "query" and its key "name". So if the node would output this data:
|
This one would return "My name is: " and then attach the value that the node with the name "Webhook" outputs and there select the property "query" and its key "name". So if the node would output this data:
|
||||||
|
|
||||||
|
|
|
@ -75,9 +75,9 @@ Example:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// Returns the value of the JSON data property "myNumber" of Node "Set" (first item)
|
// Returns the value of the JSON data property "myNumber" of Node "Set" (first item)
|
||||||
const myNumber = $item(0).$node["Set"].data["myNumber"];
|
const myNumber = $item(0).$node["Set"].json["myNumber"];
|
||||||
// Like above but data of the 6th item
|
// Like above but data of the 6th item
|
||||||
const myNumber = $item(5).$node["Set"].data["myNumber"];
|
const myNumber = $item(5).$node["Set"].json["myNumber"];
|
||||||
|
|
||||||
// Returns the value of the parameter "channel" of Node "Slack".
|
// Returns the value of the parameter "channel" of Node "Slack".
|
||||||
// If it contains an expression the value will be resolved with the
|
// If it contains an expression the value will be resolved with the
|
||||||
|
@ -93,7 +93,7 @@ const channel = $item(9).$node["Slack"].parameter["channel"];
|
||||||
Works exactly like `$item` with the difference that it will always return the data of the first item.
|
Works exactly like `$item` with the difference that it will always return the data of the first item.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const myNumber = $node["Set"].data['myNumber'];
|
const myNumber = $node["Set"].json['myNumber'];
|
||||||
|
|
||||||
const channel = $node["Slack"].parameter["channel"];
|
const channel = $node["Slack"].parameter["channel"];
|
||||||
```
|
```
|
||||||
|
|
|
@ -293,7 +293,7 @@ export default mixins(
|
||||||
if (outputData.hasOwnProperty('json')) {
|
if (outputData.hasOwnProperty('json')) {
|
||||||
const jsonDataOptions: IVariableSelectorOption[] = [];
|
const jsonDataOptions: IVariableSelectorOption[] = [];
|
||||||
for (const propertyName of Object.keys(outputData.json)) {
|
for (const propertyName of Object.keys(outputData.json)) {
|
||||||
jsonDataOptions.push.apply(jsonDataOptions, this.jsonDataToFilterOption(outputData.json[propertyName], `$node["${nodeName}"].data`, propertyName, filterText));
|
jsonDataOptions.push.apply(jsonDataOptions, this.jsonDataToFilterOption(outputData.json[propertyName], `$node["${nodeName}"].json`, propertyName, filterText));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jsonDataOptions.length) {
|
if (jsonDataOptions.length) {
|
||||||
|
|
|
@ -127,7 +127,7 @@ export class WorkflowDataProxy {
|
||||||
get(target, name, receiver) {
|
get(target, name, receiver) {
|
||||||
name = name.toString();
|
name = name.toString();
|
||||||
|
|
||||||
if (['binary', 'data'].includes(name)) {
|
if (['binary', 'data', 'json'].includes(name)) {
|
||||||
let executionData: INodeExecutionData[];
|
let executionData: INodeExecutionData[];
|
||||||
if (shortSyntax === false) {
|
if (shortSyntax === false) {
|
||||||
// Long syntax got used to return data from node in path
|
// Long syntax got used to return data from node in path
|
||||||
|
@ -180,7 +180,7 @@ export class WorkflowDataProxy {
|
||||||
throw new Error(`No data found for item-index: "${that.itemIndex}"`);
|
throw new Error(`No data found for item-index: "${that.itemIndex}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name === 'data') {
|
if (['data', 'json'].includes(name as string)) {
|
||||||
// JSON-Data
|
// JSON-Data
|
||||||
return executionData[that.itemIndex].json;
|
return executionData[that.itemIndex].json;
|
||||||
} else if (name === 'binary') {
|
} else if (name === 'binary') {
|
||||||
|
@ -275,15 +275,17 @@ export class WorkflowDataProxy {
|
||||||
const dataProxy = new WorkflowDataProxy(this.workflow, this.runExecutionData, this.runIndex, itemIndex, this.activeNodeName, this.connectionInputData);
|
const dataProxy = new WorkflowDataProxy(this.workflow, this.runExecutionData, this.runIndex, itemIndex, this.activeNodeName, this.connectionInputData);
|
||||||
return dataProxy.getDataProxy();
|
return dataProxy.getDataProxy();
|
||||||
},
|
},
|
||||||
|
$json: {}, // Placeholder
|
||||||
$node: this.nodeGetter(),
|
$node: this.nodeGetter(),
|
||||||
$parameter: this.nodeParameterGetter(this.activeNodeName),
|
$parameter: this.nodeParameterGetter(this.activeNodeName),
|
||||||
|
$workflow: this.workflowGetter(),
|
||||||
};
|
};
|
||||||
|
|
||||||
return new Proxy(base, {
|
return new Proxy(base, {
|
||||||
get(target, name, receiver) {
|
get(target, name, receiver) {
|
||||||
if (name === '$data') {
|
if (['$data', '$json'].includes(name as string)) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return that.nodeDataGetter(that.activeNodeName, true).data;
|
return that.nodeDataGetter(that.activeNodeName, true).json;
|
||||||
} else if (name === '$binary') {
|
} else if (name === '$binary') {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return that.nodeDataGetter(that.activeNodeName, true).binary;
|
return that.nodeDataGetter(that.activeNodeName, true).binary;
|
||||||
|
|
Loading…
Reference in a new issue