简体   繁体   中英

Get "Value" from simple JSON using "Key" as variable Azure Logic Apps

I have defined a simple JSON

{
  "12345": "Numbers",
  "AAAAA": "AllAs",
  "ABCXYZ": "AtoZ"
}

All I want to extract the value of "Key" when passed as a variable. I have tried body('Parse_JSON')['name'] but its failing.

I just want to get the value of what ever Key I am looking for as variable. 在此处输入图像描述

As per your comment as you are initializing ABCXYZ value and that you have already declared in inputs you can just type ABCXYZ in value rather than calling Name variable

在此处输入图像描述

Figured it !

body('parse_JSON')?[variables('name')]

The above does the following:

1- body('parse_JSON') gets the body of Parsed JSON

2- ?[variables('name')] gets the value of name which is equal to ABCXYZ

3- Returns AtoZ

For those also just starting with logic apps - if its not immediately apparent;

At "Initialize Variable 2" you need to use the "Expression" tab to input the line

body('parse_JSON')?[variables('name')]

I just want to add something here as I was looking for a way to use a dynamics value passed in to then use that to look up in a json body to translate that value to a different.

Mapping value eg. {"male":"M", "female":"F", "Non-Specific":"O"}

So I receive the value "Male" but I need that to return as M

to achieve this in a logic app the above partially gets you there.

body('Parse_JSON_gender_mapping')?[string(variables('received_gender'))]

I had to wrap my use of the variable for the value we received in string() function, even though the value was a string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM