Python Task return Json || Parse in orquesta workflows

hi Team

in my workflow, calling one of the Python script tasks & got the stdout as JSON format.

stdout: ‘{’‘short_description’’: ‘‘host1 is not responding to Ping’’, ‘‘description’’: ‘‘host1 is not re
sponding to Ping’’, ‘‘’’: ‘‘host1’’, ‘‘state’’: ‘‘7’’, ‘‘’’: ‘‘Wintel L1’’}

we need to parse the json values inside the workflow. i have tried to get the description as below

  • inc_description: “{{ result().stdout.description }}”
    however i got an error - - message: ‘JinjaEvaluationException: There are unresolved variables: result().stdout.description’

Please help.

action: arul_automation.GetIncident
Incident_Number: “{{ ctx().incident_no }}”
Field_name: “number,description,short_description”
- when: “{{ succeeded() }}”
- inc_description: “{{ result().stdout.description }}”
- error_message: “{{ result().stderr }}”
- noop
- when: “{{ failed() }}”
- error_message: “Could not get the details for this incidnet {{ ctx().incident_no }}”
- noop

It’s difficult to say without seeing the output from the first task.

But it indicates that it can’t find description under stdout.

What you see in the return from "st2 execution get " under the result field, is what result() should return, and be able to handle.

Some things to check:

  • Check stdout is at the level you expect, and not at something like result().result.stdout
  • Check that it is being picked up as JSON (in execution get - has it unpacked it as JSON), I’ve known some tasks return a string encoding of the JSON rather than the JSON itself
  • Perhaps start higher up with your variables, e.g. check what result() returns, then result().stdout - to see exactly what you are getting.