Pretty Print JSON within Flows

Pretty Print JSON within Flows

Some weeks ago I prepared my presentation about AI Foundry Content Understanding for the Baltic Summit 2025 at Gdansk, Poland. In detail, I have built a small model-driven app as frontend for my demo. My goal was to upload first my PDF file into my Dataverse table from my app. Next, I would start my automation scenario based on Power Automate flows. After completion of my content understanding analyzer, I would then show the resulting JSON in my app. So, my challenge was: I must convert the minimized JSON into a pretty print JSON within my Power Automate flow.

My whole automation example was built with Power Automate. But there is no action in which I can use to pretty print my JSON in a flow.

What can I do? I can pretty print the JSON in Power Fx. Right, I could add a custom page to my model-driven app. There, I can use Power Fx to format the JSON. But this means I must add a piece of canvas app to my demo. Isn’t there simple solution for my problem?

Defining a Function

Yes, there is a simple solution that solves my problem! I can utilize a Dataverse Function. Here I can write Power Fx code. I can also call this function directly with an Unbound Action from my Power Automate flows. This means, I can use Power Fx to pretty print my JSON in a flow. Perfect, let us start!

First, I’m creating a new function in my Dataverse solution. Here, I’m clicking on New | Automation | Function in my Dataverse solution:

Afterwards the New function editor opens. Here I set up the property Display Name with value Content Understanding Format JSON. I’m adding a description as well to my new function. In addition, I define an input parameter json and an output parameter formattedJson:

Furthermore, I’m using this code snippet as Formula:

With(
    {j: ParseJSON(json)},

    {formattedJson: JSON(j, JSONFormat.IndentFour)}
)

Let me explain my code. I’m utilizing the With function to define a local variable j where I first store the parsed JSON. This means, j is an object. In the last line of my statement, I must define my function result. In other words, here I return a record with the property formattedJson.

I’m utilizing the Power Fx function JSON with the parameter JSONFormat.IndentFour. This Power Fx function now returns my object j as text with an indentation. In detail, my output contains a newline for each column and nesting level. Furthermore, it uses four spaces for each indentation level.

Finally, I’m saving my new function.

Calling my Dataverse Function

Now it is time to integrate this function into my Power Automate flow Process Document. I do this directly after my action Parse Result JSON. Here I’m adding the action Perform an unbound action and select my function mme2k_ContentUnderstandingFormatJSON as Action Name:

In addition, I’m using this expression to select the returned fields collection as parameter json:

first(body('Parse_Result_JSON')?['contents'])?['fields'] 

Afterwards, I’m using the result of my function mme2k_ContentUnderstandingFormatJSON as parameter Result JSON in my next action. This stores the pretty printed JSON in my updated record. The result is a well formatted JSON that I can show in my model-driven app:

Perfect!

Summary

With just a few steps, I was able to solve my problem. I pretty printed JSON in a Power Automate flow. Instead of building extra UI elements or switching to a canvas app, I created a Dataverse Function with Power Fx. This allows me to parse and format JSON directly in my automation scenario. Furthermore, I can call the function from my flow through an unbound action. The result JSON is now a well-structured output that I can easily store and display in my model-driven app.

A Dataverse Function is a simple solution that allows me to utilize Power Fx code in my automation scenarios!

Share

Leave a Reply