Logic Apps : How to get the display_value response

2019-08-21 15:53发布

问题:

In Azure Logic app, the response I am getting while I am making an Http response call is below.

{
 "import_set": "",
 "staging_table": "",
 "result": [
   {
    "transform_map": "",
    "table": "incident",
    "display_name": "",
    "display_value": "INC5164816461631654",
    "record_link": "",
    "status": "",
    "sys_id": ""
   }
 ]

}

How I can get the 'display_name' property. I tried several ways like

@triggers().outputs.body.result.display_name

@{body('HTTP')['result'][display_name]}

but it's not working.

Result: INC5164816461631654

回答1:

If your output is in json format, you could just get it with a expression:@body('HTTP')['result'][0]['display_name']. Cause under tag result it's array, so if you don't point the index, it won't be able to find the property.

And if your output is not json format, it will be a string. you need to parse it to json. Then you will be able to use same expression(@body('Parse_JSON')['result'][0]['display_name']) to get the value.



回答2:

Couple of ways to do this:

  1. If you are using directly from the response try this expression as below: directly on expression : triggerBody()?['result'][0]?['display_name'] or in Code view like this @triggerBody()?['result'][0]?['display_name'] the response should be a proper JSON.
  2. If it is not a proper json use Parse json with the payload schema and use the below expression : body('Parse_JSON')?['result'][0]?['display_name'] or in code view as @body('Parse_JSON')?['result'][0]?['display_name']. Note replace the parse_json with your corresponding shape name.
  3. By declaring Variables as mentioned by George but this would increase the flow, rather you can directly use the expression to extract the value.

Let me know if this helps! Cheers