Function node injecting information with its quotes

I am using a function node to grab information from a message. but it is pulling the quotes "[{ around the array causing it to read it as one entire item rather than an array. how do i prevent the function node from grabbing the quotes?

the image below is the current function node config

Not clear where that data is coming from but it is a string representation of JSON data. You can pass it through a json node to get the actual data.

Or, in a function node, you can use JSON.parse. However, you should always wrap JSON.parse function calls in a try {...} catch (err) {...} wrapper because those functions fail in a nasty way.

How are you setting the flow variable MDF?

so when i run it through a json node, it turn back into an object, but then how do i get it into my function node for it to be represented in the data i need it in?

[{"a":"1","b":"0004a3fd2db9","c":"MDF Gi1/0/36"},{"a":"1","b":"P1_EMP_PARK_L2","c":"MDF Gi1/0/24","d":""},{"a":"1","b":"P1_EMP_PARKS","c":"MDF Gi1/0/43","d":""},{"a":"1","b":"P1_COFFEE_ROOM","c":"MDF Gi1/0/7","d":""}]

when i put this data into the "items:" line it works just fine then changes the data into an object and has these items as an array properly

but when i pull the information through a referenced flow it pulls the data like this "[{"a":"1","b":"0004a3fd2db9","c":"MDF Gi1/0/36"},{"a":"1","b":"P1_EMP_PARK_L2","c":"MDF Gi1/0/24","d":""},{"a":"1","b":"P1_EMP_PARKS","c":"MDF Gi1/0/43","d":""},{"a":"1","b":"P1_COFFEE_ROOM","c":"MDF Gi1/0/7","d":""}]" with quotes encapsulating the json array.

i dont really know how else to get this array into the referenced function node

yes, flow.MDF gets populated when i run my ansible script.

when i run the function node, it pulls the information from the flow variable, it just also encapsulates the data in quotes :confused:

i got it figured out. you were right about running it through the json file. but i had to first let it go into the flow node, recycle it self through a json file and reset the flow node.

for some reason if i sent it directly into the flow node as a json object it was just injecting the word object over and over.

you are awesome my man!! thank you :slight_smile:

When it comes from Ansible it will be a string (that is what the quotes are telling you, the quotes are not really there it is just the way that a string is identified). Ideally you should send it through a JSON node when it comes in from Ansible, and use the result to set the flow variable, rather than setting the flow variable with a string and then trying to sort it out later.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.