Fenomatik
Fenomatik

Reputation: 477

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.enter image description here

Upvotes: 0

Views: 4505

Answers (4)

Nataku62
Nataku62

Reputation: 43

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.

Upvotes: 0

jon
jon

Reputation: 11

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')]

Upvotes: 1

Fenomatik
Fenomatik

Reputation: 477

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

Upvotes: 0

SaiSakethGuduru
SaiSakethGuduru

Reputation: 2440

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

enter image description here

Upvotes: 0

Related Questions