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

**URL:** <https://discourse.nodered.org/t/how-to-pass-json-data-to-a-python-script-in-exec-node-in-node-red/57249>\
**Category:** General\
**Created:** [26 January 2022 10:25 UTC](https://discourse.nodered.org/t/how-to-pass-json-data-to-a-python-script-in-exec-node-in-node-red/57249 "2022-01-26T10:25:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zekitui](https://avatars.discourse-cdn.com/v4/letter/z/65b543/32.png) [@Zekitui](https://discourse.nodered.org/u/Zekitui)\
**Post date:** [26 January 2022 10:25 UTC](https://discourse.nodered.org/t/how-to-pass-json-data-to-a-python-script-in-exec-node-in-node-red/57249/1 "2022-01-26T10:25:51Z")

</div>

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

```auto
{
"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 :

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/a/3a244bf93848d9992e29e5dcdcfcd6ce29356487.png)

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 January 2022 10:35 UTC](https://discourse.nodered.org/t/how-to-pass-json-data-to-a-python-script-in-exec-node-in-node-red/57249/2 "2022-01-26T10:35:08Z")

</div>

> [@Zekitui](#):
>
> Here is the format of my json

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

> [@Zekitui](#):
>
> It works when i inject in the msg.payload a string but with a json it doesn't work anymore

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [27 March 2022 10:35 UTC](https://discourse.nodered.org/t/how-to-pass-json-data-to-a-python-script-in-exec-node-in-node-red/57249/3 "2022-03-27T10:35:55Z")

</div>

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