0

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 this supported to use variables in key reference for JSON

  • It should work, it works for me. Can you show us your flow so we can try and replicate the issue exactly? – Skin Feb 28 '23 at 10:25

1 Answers1

1

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
vijaya
  • 1,525
  • 1
  • 2
  • 6
  • Thanks @vijaya. Yes its working once I hard coded the values. Not sure why in my variable the value is coming as 'FY23-01\n\n' which is causing blank response. – vivek mishra Feb 28 '23 at 13:09