Execute Command $items?

Following the recommendation to use Execute Command when trying to write scripts in anything else but node, I build my own version of the docker image with my preferred runtime included, and now at the point where I try to access the data from the previous node, just like in Function the items, or in Function Item the item ( node ).
Is the data available in some environment variable or file location?

Welcome to the community @user23

So you want to access data from a previous node if the execute command? If so, you can use expressions

https://docs.n8n.io/nodes/expressions.html#method-items-nodename-string-outputindex-number-runindex-number

That looks “almost” good enough, with Expressions you can get a selected field of one of the item of the input data, so like “json[0].field”, where what I’m looking for is “json”.

Hey @user23!

If you want the whole JSON object, you can refer to the json, don’t specify any fields. Let me know if you need more explanation :slight_smile:

Yes @harshil1712 I do need more explanation
echo “{{$json}}”
give me only
[object Object]

In edit view it looks OK… but when saved it breaks.

Here is a full workflow for example.

You will have to convert the JSON object to a string which will let the Shell print it. You can use the JSON.stringify() method to do that.

Here’s the updated workflow:

I tested the workflow you posted, and that does address the single property per item issue, but still just one item. So now it’s we got from json[0].field up till json[0], but still not down to json.

So in this example, the “Execute Command” will have only one of the release ( the latest ), not the full data. ( comparing to a Function where I can use return items and I get all the releases )

If you want to return all the items, then in that case you might have use $items(). Here’s the documentation that might be helpful for you: https://docs.n8n.io/nodes/expressions.html#method-items-nodename-string-outputindex-number-runindex-number

As I know almost nothing about node.js it’s quite a hard guess game at this point, but I’m getting closer.

cat << EOF
{{$evaluateExpression(JSON.stringify($items()))}}
EOF

This work at least up to the point of getting me back everything, even if the structure is messed up.
If I manage to get the original json that would be fabulous otherwise I will just go with this as it is.

$items() will give you the JSON. Can you please help me understand what exactly you mean by “Original JSON”? Do you want the exact response that the endpoint returns?

{{$evaluateExpression($items())}}

gives me

[object Object],[object Object]....

{{$evaluateExpression(JSON.stringify($items()))}}

gives me

[ 
  {"json":
    {"title":"[email protected]",
    "link":"https://github.com/n8n-io/n8n/releases/tag/n8n%400.125.0"....}},
  {"json":
    {"title":"[email protected]",
    "link":" ....

What I’m looking for, or just hoped for at least, is the source data in json, and not in node.js json object.
Something like:

[ 
    {"title":"[email protected]",
    "link":"https://github.com/n8n-io/n8n/releases/tag/n8n%400.125.0"....},
    {"title":"[email protected]",
    "link":" ....

The other way would be to wrap them in an array and create a single item and refer to this item. You can check the code snippet for modifying the structure here: JavaScript Code Snippets | Docs

Wow that took much longer then I expected, and It’s way more complicated then I ever imagined, but the important thing is that it works.
There is a sample workflow which implement the basic functionality.

@RicardoE105 @harshil1712 Thanks for the help!

1 Like