azure-logic-apps

I need to pick a specific value from an array


I have an output response from the HTTP request as shown below

"body": {
        "ShipmentResponse": {
            "Notification": [
                {
                    "@code": "0",
                    "Message": null
                }
            ],
            "PackagesResult": {
                "PackageResult": [
                    {
                        "number": ,
                        "TrackingNumber": 
                    },
                    {
                        "number":,
                        "TrackingNumber": 
                    }
                ]
            },
            "LabelImage": [
                {
                    "LabelImageFormat": "PDF",
                    "GraphicImage": "Value required"
                 }
            ],

From the above response I need to fetch only the GraphicImage value.

I tried by using a array variable anf Filter array but LabelImageFormat and Graphic Image is treated as one single Index, as a result of which I am unable to fetch a single value.

Please let me know how I can fetch only the value required that is Graphic Image.

"GraphicImage": "Value required"

Thanks in Advance


Solution

  • This should be easy with ParseJson Action.

    1. Parse the JSON:

      After receiving the HTTP response, add a 'Parse JSON' action.

      For the content, provide the body of the HTTP response (e.g., outputs('HTTP_action_name').body).

      For the schema, you can use the sample payload you provided to generate it.

    2. Extract the GraphicImage Value:

      After parsing the JSON, you can access the GraphicImage value directly through the outputs of the 'Parse JSON' action.

      Add a new action (like 'Set variable' or 'Compose') and for its value, use the following expression:

      outputs('Parse_JSON_action_name')?['body/ShipmentResponse/LabelImage'][0]?['GraphicImage']
      

      Replace Parse_JSON_action_name with the name of your 'Parse JSON' action.

    3. Use the Value:

      After the above step, the GraphicImage's value will be stored in the variable or the Compose action. You can then use it in subsequent steps of your Logic App as needed.