This is a very useful tip that makes working with JSON content in Power Automate much easier!

I’ve discussed in previous posts how to understand and navigate a JSON structure, so if you need guidance with this, then check out the following:

Simplify JSON Content Before Parsing

When interacting with other platforms in Power Automate, JSONs are part of everyday life. Often JSONs are large, intimidating and sometimes chellenging to navigate. However, the Select action is your friend and can be very helpful to hone in on the specific section of JSON that you are interested in and discard the rest.

Below is a demo flow that connects to ChatGPT and extracts the response. Let’s go through each action step by step.

Action 1 - Manually Trigger A Flow

The flow is triggered manually.

Action 2 - HTTP

The HTTP action sends a prompt to ChatGPT which outputs the JSON shown below. This is typical of a JSON that you’d want to simplify before extracting the data, because it includes a lot of content that I’m not interested in. In this example, I want to extract the main output which is the ‘details’ section on technology trends.

{
  "choices": [
    {
      "content_filter_results": {
        "hate": {
          "filtered": false,
          "severity": "safe"
        },
        "violence": {
          "filtered": false,
          "severity": "safe"
        }
      },
      "finish_reason": "stop",
      "index": 0,
      "logprobs": null,
      "message": {
        "content": {
          "summary": "Key Trends in Technology",
          "details": [
            {
              "trend": "Artificial Intelligence",
              "description": "AI advancements are accelerating, with generative AI and natural language processing leading the field. Applications are growing in healthcare, finance, and customer service.",
              "examples": [
                "ChatGPT",
                "Google Bard",
                "DALL-E"
              ]
            },
            {
              "trend": "Cybersecurity",
              "description": "With increased digital transformation, there is a growing focus on cybersecurity to protect data and privacy, especially in the cloud and IoT spaces.",
              "examples": [
                "Zero Trust Architecture",
                "Multi-Factor Authentication",
                "Quantum Encryption"
              ]
            },
            {
              "trend": "Quantum Computing",
              "description": "Quantum computing is showing promise in solving complex problems that classical computers struggle with, such as large-scale simulations and cryptography.",
              "examples": [
                "IBM Quantum",
                "Google Sycamore",
                "D-Wave"
              ]
            }
          ],
          "forecast": "These trends are expected to shape the future, with AI and cybersecurity at the forefront of technological advancements in the coming decade."
        },
        "role": "assistant"
      }
    }
  ],
  "created": 1731241794,
  "id": "chatcmpl-AS1MgJow4Gfz1yG4GSdN183w4q205",
  "model": "gpt-4o-mini",
  "object": "chat.completion",
  "prompt_filter_results": [
    {
      "prompt_index": 0,
      "content_filter_results": {
        "hate": {
          "filtered": false,
          "severity": "safe"
        },
        "violence": {
          "filtered": false,
          "severity": "safe"
        }
      }
    }
  ],
  "system_fingerprint": "fp_d54531d9eb",
  "usage": {
    "completion_tokens": 500,
    "prompt_tokens": 10666,
    "total_tokens": 11166
  }
}

Action 3 - Compose

The Compose action allows me to target a specific element of a JSON navigating from the root to the required content, in this case the ‘details’ array:

outputs('Compose')?['choices'][0]['message']['content']['details']

For guidelines on how to construct the above query, see my recent post Navigating a JSON Structure.

When the flow is run, the output from the Compose action is show below. As you can see all the superfluous info in the JSON is now removed leaving an array containing just the info I’m wanting. It is now much easier to work with.

[
{
"trend": "Artificial Intelligence",
"description": "AI advancements are accelerating, with generative AI and natural language processing leading the field. Applications are growing in healthcare, finance, and customer service.",
"examples": [
"ChatGPT",
"Google Bard",
"DALL-E"
]
},
{
"trend": "Cybersecurity",
"description": "With increased digital transformation, there is a growing focus on cybersecurity to protect data and privacy, especially in the cloud and IoT spaces.",
"examples": [
"Zero Trust Architecture",
"Multi-Factor Authentication",
"Quantum Encryption"
]
},
{
"trend": "Quantum Computing",
"description": "Quantum computing is showing promise in solving complex problems that classical computers struggle with, such as large-scale simulations and cryptography.",
"examples": [
"IBM Quantum",
"Google Sycamore",
"D-Wave"
]
}
]

Action 4 - Parse JSON

I run the flow containing just the first 3 actions and I copy the above schema from the output of the Compose action. I then create the Parse JSON action and set its content to the output of the preceding Compose action. I then paste the schema into the Parse JSON action as ‘Generate from sample’.

Action 5 - Select

Finally I create a Select action which demonstrates the benefit of reducing the complexity of the JSON. As can be seen below, I can now use the Dynamic content to easily select the keys that I require. I wouldn’t be able to do this if I hadn’t simplified the JSON first as this info is deep inside the original JSON so is not selectable. Instead I would have to manually construct the query, which is more complicated to do.

I can now access my required data as the output of the Select action, for example to save to Dataverse.

So there you have it. Make your life easier by first use a Compose action to simplify your JSON before parsing!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top