Right now, I'm creating a REST API with node-red which took an HTTP in as the input, process the HTTP get parameters with python using exec, and try to send the response with JSON format.
In exec node, the output is sending out as stdout with Python print function, but I'm stuck in how to format the stdout as JSON string. Link print("{'error': 123}") with template of {{ payload}} then Set Headers and http response does not work in my case.
Any suggestions would be appreciated. I've the freedom to either format the print function from my python code or directly modifly the node-red template.
Edited: I figured out. The template of {{ payload}} is not necessary and it would try to escape the quotation marks. Simply print('{"error": 123, "dfsfsfs": 456}') and link exec to http response is good enough.
My python code needs to process data from database and machine learning models, I'm not very familiar with using node-red/JS to achieve the same objectives, that's why I'm only using node-red to do a simple parse HTTP query task.