I am trying to compare two columns from a sheet every day. There is an IF node to proceed to the next step. Since my sheet header is the current day, it is dynamic. How can we standardize the names, e.g., col-1, col-2, instead of ‘2024-04-22’, ‘2024-04-21’, so that we can use them as expressions for the IF node?
Here is a pretty static but clean solution if you always know the number of columns you will have to deal with.
You can get an array of the keys using the .keys() method. A key is the name of a value in json.
Then you can use that key to query the json just like how you were.
Use an edit fields node and manually name the columns then use: {{ $json[ $json.keys()[1] ] }} in the value to get the value of that index of json. Increment the 1 for each new value.
I started at one instead of 0 because 0 would be the row numbers
See the node below
You can also just do this straight into the if node, but this may make it a little easier to know what’s happening.
Also, this will only work if you have no other data in your json
You just have a few typos. I explained below but just go to the bottom and copy the last thing and that should work
You can access a key in two ways, dot and bracket notation (json.key and json['key'])
You need to use brackets of there is any spaces or if it is an expression.
$json.keys() is a method (aka a function) to get an array of the keys. Then if we add a number in brackets to the result of that, we get the item at that index in the array. $json.keys()[1] means the second key in the list
So you need to query your json by that second key in the list {{ $json[ $json.keys()[1] ] }}
Now I want to replace my whole static JSON array. I have tried $input.all() does not work as expect. I have also tried $input.all()[0].json. It shows ERROR… Any idea how could we retrieve the JSON array from from the previous node? Thanks…