This is mostly due to my lack of knowledge in JS and NodeJS.
I have an “Execute Command” node that returns json in stdout; and I am trying to access it in another node to set a custom message if one of the properties is true.
So I am trying the following but it seems it only outputs the exact same data it received:
const input = $node["DL from Telegram"].data["stdout"];
const result = JSONparse(input)
return result;
I hope that helps. It emulates a command returning JSON and then shows an example of how to bring the data in the flow and another one on how to use the data directly.
It did help. Your comment about the HTTP module made me go back to it and realise I missed a step in configuring it the first time.
Since it returns JSON I was able to set the variable in the way I wanted.
I also found an issue when running the Function Node, it sometimes hangs when I am trying to set a variable using an if statement. I’ll see if I can gather more information about it and make sure it’s not a problem on my side.
Ah great to hear that it helped and you got it working!
Currently not aware of any issues there. Which sadly does not mean much like for any bug If you found one, would be really great to get a workflow where it can be reproduced that I can fix it asap.
This post is still the top result for searching for JSON conversion but since the Code block has been changed the sample isn’t working, can you update this post with a latest working example ?
PS.: It’s a pretty common use-case where the return data isn’t what n8n think it is, html rather then text or json rather then text, string rather then number, maybe a convert module would make sense, or the SET module would have an option to change data type, or something similar.
The code used for JSON conversion in the Code block as below:
// Loop over input items and add a new field called 'myNewField' to the JSON of each one
for (const item of $input.all()) {
item.json.stdout = JSON.parse(item.json.stdout);
}
return $input.all();