1

I am using two steps in Nifi:

Step 1. InvokeHTTP processor to make a REST API call and receive a JSON response, "Put Response Body In Attribute" used to store the JSON response into an attribute.

Step 2. ExecuteStreamCommand processor to invoke Python script. The JSON response attribute from previous passed as input argument here.  The Command Argument to the processor:

/home/kavipriya/script/Scaling.py;"${AssetModel}";

But Double quotes are removed from the JSON message and then passed to python script. So when parsing JSON I'm getting following error:

"json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 3 column 5 (char 10)"

Can someone tell me why are the double quotes removed when JSON message passed as argument and also if there is an option to retain the double quotes.  Thanks for your help!

I have attached JSON message and also the python logs showing double quotes missing when reading the argument.JSON Attribute with doublequotes passed to Python scriptLog written by Python script missing double quotesNifi flow with errorPython Script

Kavipriya M
  • 131
  • 5
  • 1
    the passing of double-quoted parameters through command line is quite tricky because the shell (batch) also uses double-quotes as a delimiter of the parameters. try to use dynamic properties in ExecuteStreamCommand to pass json through environment variable. – daggett Oct 01 '19 at 09:22
  • 1
    @daggett- Thanks for you quick reply. I managed to find a workaround for this. After the InvokeHTTP, I used ReplaceText and ExtractText processors to prefix all double quotes with escape character "\" and then passed it as an argument to python script. But even then the double quotes were missing, but escape character '\' was intact in the message. Then I used a string.replace("\\","\"") function in python to replace all escape characters back to double quotes. Its working for me now :) Thanks for your help! – Kavipriya M Oct 01 '19 at 11:47

0 Answers0