Search code examples
jsonazure-logic-apps

Access parsed json key using a variable in Logic App


Can we access parsed JSON key using logic app variable?

I have a string type variable with value as FY23-01 like below:

enter image description here

And a parsed JSON like below:

{
  "@odata.etag": "",
  "FY23-01": "1",
  "FY23-02": "2",
  "FY23-03": "3",
  "FY23-04": "4",
}

Now I want to get the value of key "FY23-01". I am using below expression and it always returns blank:

body('Parse_JSON')?[variables('secondContent')]

Is it supported to use variables in key reference for JSON?


Solution

  • Yes it is supported to use variables in key reference for JSON.

    The expression body('Parse_JSON')?[variables('secondContent')] should work to access the value from Json.

    One of the alternative approach is using this expression outputs('Parse_Json')?['body']?[variables('secondContent')]. I have tried in both the ways and below are steps I followed,

    • Created logic app shown below, enter image description here
    • From http trigger sending below json and using parse json action to parse json received from http request trigger. enter image description here enter image description here
    • Initialized variable as shown below, enter image description here
    • Initialized another variable to store value of json key with the expression outputs('Parse_Json')?['body']?[variables('secondContent')], enter image description here
    • Logic app ran successfully and output is, enter image description here
    • One of the other approach is selecting key from directly parse json as shown,

    enter image description here

    • I have used expression body('Parse_JSON')?[variables('secondContent')], this also worked and got result. enter image description here output: enter image description here