The workflow uses a Function node to mock the data. The first return statement in the Function node returns an empty object, similar to what you receive. In the IF node, I am checking if the userId is present or not. Since we are returning an empty object, the userId is not present. Hence, in this case the IF node will return.
If you comment out the first return statement, and the Function node will now return a userId. When you execute the IF node, this time it will return false, since the userId is present.
Really helpful thanks ! Makes everything much clearer for me for how to search in the json output via specific fields to see if they exist or not… also got me to understand the function node better for testing/debugging before connecting.
That’s perfect! The Function node I used here was just for demonstration. You can always throw one in your workflow if you want to test things out, but their real power lies in the ability of writing custom code!
You can also use a ternary operator in your If statement, If you set the input as Bool then click on the cog and add an expression you can do something like:
{{$json["general"] ? true : false}}
What this will do is return True if the key exists and False if it doesn’t…
Yes It’s clearer now. There’s a follow up question that I have as it might help tohers who are using the phantombuster node. The node output data from phantombuster is an array of the profile information, but I only want the last item in the array, separated out as a single item. See the attached image
I assume this could be done using the function node with some custom java script yes? I’m able to access the correct data in the rest of the work flow via the following parameter path : {{ $item($items.length+2).$node[“Phantombuster”].json[“details”][“mail”] }}
I’m having some difficulty pulling only the last item from the array and outputting it into a new array. At the moment the best I’ve been able to do is replicate the array in a new array. I must be missing something somewhere? Where as what I want is to create a new array that contains only the last entry of the output array from the Phantombuster node.