How to pass json data to a python script in exec-node in node-red

I'm new to node-red, and I wish I knew how to pass json data into a python script with node exec. Here is the format of my json

{
"fftx": [
    2.6347945642924716e-17,
    0.002915638633219862,
    0.0003399789406291348,
    0.0003993145353719118,
    0.0016444053046928743,
    0.0011306178953261797,
    0.0008362894402139914,
    0.0009057875156523967,
    0.0013899906897498193,
    0.0020831589124456714,
    0.0028930687879060012,

I added a function node in order to put in the msg.payload only the msg.payload.fftx like this :

in the exec node I wrote : python3 /home/admin/script2.py msg.payload

and I try to retrieve the data in my script with this command: data=(sys.argv[2])

It works when i inject in the msg.payload a string but with a json it doesn't work anymore

Thanks for you help

I assume that is not the full example right? (as it is not valid JSON)

In case you are not aware, JSON is a string (JavaScript Object Notation) so do you mean it doesnt work if you send a JavaScript Object?

If that is the case, then send the JS Object through a JSON node first to convert it from a JS Object to a JSON String - then send to the exec.

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