0

I am trying to store an API response in attribute myAttr in extractText processor but when I am trying to print the value of myAttr in ExecuteScript it is giving [object Object] in output and not printing the entire response of the API.

I think it can be done EvaluateJsonPath processor but I couldn't understand how.

Execute Script:

var reasonId = []
try {
  var reasonId = JSON.parse(flowFile.getAttribute('SubReason1'));
  if (flowFile != null) {
    if(reasonId != undefined){
      flowFile = session.putAttribute(flowFile, 'myAttr', reasonId);
    }
    else{
      session.transfer(flowFile, REL_FAILURE)
    }
    session.transfer(flowFile, REL_SUCCESS)
  }
}

Output is in myAttr, the expected output is the entire response of the API.

enter image description here

paleonix
  • 2,293
  • 1
  • 13
  • 29
Destiel
  • 35
  • 6

1 Answers1

0

Try

JSON.stringify(myAttr)

The output [object Object] is telling you that myAttr contains an object. JSON.stringify() should convert the object to a readable String, just like JSON.parse() converts the JSON String to an object.

Caleb
  • 69
  • 4
  • is it possible to do it like this in NIfi executeScript processor? – Destiel Apr 27 '23 at 11:29
  • I'm not sure, but if JSON.parse() works, then I would expect JSON.stringify() to work on the result. Have you tried it out? I don't see the code where you're printing out the value of myAttr. It's possible that the content in myAttr is correct, but you just need to apply JSON.stringify() to it when printing out the result. – Caleb Apr 27 '23 at 15:39