EvilDr
EvilDr

Reputation: 9610

How to specify JSON node property values when parsing/iterating in Azure Logic Apps?

TL;DR How do I specify a specific JSON node property within Azure Logic Apps' ParseJSON > For Each step, when the designer only gives me access to the parent nodes?

I'm building a Logic App that:

  1. Receives and parses a list of people as JSON data from an external system
  2. Constructs a new JSON file with different structure
  3. Posts the new file to a second external system

The JSON response from item 1 has this structure:

{
    "Success": true,
    "Message": "Completed",
    "Result": [
        {
            "EmployeeId": {
                "DisplayValue": "PW123",
                "FieldHistory": []
            },
            "EmailId": {
                "DisplayValue": "*****.*****@******.co.uk",
                "FieldHistory": []
            }
        },
        {
            "EmployeeId": {
                "DisplayValue": "PW789",
                "FieldHistory": []
            },
            "EmailId": {
                "DisplayValue": "*****.*****@******.co.uk",
                "FieldHistory": []
            }
        },
        .... removed for brevity
    ]
}

Within the designer, if I add a Data Operations > Parse JSON > For Each step, it lets me specify the properties, but at too high a level:

enter image description here

Notice the designer gives me EmployeeId, but I actually need EmployeeId.DisplayValue, which is both properties and their values in JSON format, rather than a simple string containing only the EmployeeId or EmailId values.

Can the JSON be read at the deeper level I require using the designer?

Upvotes: 1

Views: 732

Answers (2)

EvilDr
EvilDr

Reputation: 9610

To support the input by AdAstra and provide a canonical answer for future reference...

The ForEach block was misleading, and wasn't actually required. Instead a Select block was required, but which then had to be edited in Code View (as advised by @AdAstra) to cherry-pick the desired fields:

enter image description here

enter image description here

I still need to figure out wrapping the output in my desired structure, and will update when that's solved. It turns out that reforming the JSON into a new structure is also super-simple thanks to code view. I just specified my desired output around the existing logic:

             "from": "@body('Parse_JSON')?['Result']",
             "select": {
                 "Option1": "Value1",
                 "Option2": "Value2",
                 "People": [
                     {
                         "Email": "@item()['EmailId']['DisplayValue']",
                         "FirstName": "@item()['FirstName']['DisplayValue']"
                     }
                  ]
             }

Note that Designer View does not allow for modifications to the more complex selections after specifying them in code.

Upvotes: 1

AdAstra
AdAstra

Reputation: 1984

If I am not mistaken you can do something in the lines of Parse_JSON()['EmployeeId']['DisplayValue'] <-- this is probably not the exact match, but the syntax is something like that.

They way you do this is that you either write it in code view or in the designer you start on an expression, add the blanks with dynamic content and finish by adding the ['DisplayValue'] tag.

Upvotes: 2

Related Questions