Things I wish I knew: Converting File Content to JSON

  1. Introduction
    1. Leveling Up Your Power Automate Game with Expressions
    2. Why Expressions Matter
    3. Working with JSON Files Using Expressions
    4. Real-World Example: Inspecting a File from FTP
    5. Benefits of Using Expressions
  2. Solution
    1. Step 1
    2. Step 2
    3. Step 3

Introduction

Leveling Up Your Power Automate Game with Expressions

When I first started using Power Automate, there were a few things I wish I had known that would have saved me time and frustration. One of the biggest lessons? Mastering expressions. Expressions in Power Automate are like a secret superpower that can take your automation to the next level.

Why Expressions Matter

Expressions let you handle logic and data transformations directly within your flow. For example:

• Instead of using a Condition action to validate if outputs meet specific criteria, you can use a single expression to evaluate the data inline.

• This makes your flows more efficient, cleaner, and often faster.

Working with JSON Files Using Expressions

Let’s talk about working with JSON files—a scenario many of us face when automating workflows.

Instead of:

1. Taking the content of a JSON file.

2. Saving it to SharePoint (or another location).

3. Opening the file to inspect its contents.

You simply use an expression in Power Automate to directly parse and view the content of the JSON at runtime.

For instance:

• Use the json() expression to convert file content into a readable JSON object.

• This lets you work with the data directly in the flow without needing to save or manipulate the file externally.

Real-World Example: Inspecting a File from FTP

Imagine this scenario:

• A file is generated on a server and fetched into Power Automate using the SSH – FTP connector.

• Instead of copying this file to SharePoint just to review its contents, you can apply an expression like json(outputs(‘Get_file_content’)) to convert the file content directly into JSON format.

• This approach enables you to extract, validate, or manipulate data from the file immediately during the flow’s runtime.

Benefits of Using Expressions

1. Efficiency: Skip unnecessary steps like saving files or creating extra conditions.

2. Flexibility: Work with complex data structures, like arrays and objects, without additional processing.

3. Cleaner Flows: Reduce the number of actions in your flow, making it easier to manage and debug.

Solution

Step 1

Create a Power Automate flow with a “Button” trigger.

Step 2

Add a Compose action, and in this action, write the following expression.

json(base64ToString('ewogICAgImludm9pY2VOdW1iZXIiOiAiSU5WLTAwMSIsCiAgICAiaW52b2ljZURhdGUiOiAiMjAyNC0xMS0yOCIsCiAgICAiZHVlRGF0ZSI6ICIyMDI0LTEyLTI4IiwKICAgICJjdXN0b21lciI6IHsKICAgICAgICAibmFtZSI6ICJKb2huIERvZSIsCiAgICAgICAgImFkZHJlc3MiOiAiMTIzIE1haW4gU3RyZWV0LCBDaXR5dmlsbGUsIENvdW50cnkiLAogICAgICAgICJlbWFpbCI6ICJqb2huLmRvZUBleGFtcGxlLmNvbSIKICAgIH0sCiAgICAiaXRlbXMiOiBbCiAgICAgICAgewogICAgICAgICAgICAiZGVzY3JpcHRpb24iOiAiUHJvZHVjdCBBIiwKICAgICAgICAgICAgInF1YW50aXR5IjogMiwKICAgICAgICAgICAgInVuaXRQcmljZSI6IDUwLjAsCiAgICAgICAgICAgICJ0b3RhbFByaWNlIjogMTAwLjAKICAgICAgICB9LAogICAgICAgIHsKICAgICAgICAgICAgImRlc2NyaXB0aW9uIjogIlByb2R1Y3QgQiIsCiAgICAgICAgICAgICJxdWFudGl0eSI6IDEsCiAgICAgICAgICAgICJ1bml0UHJpY2UiOiA3NS4wLAogICAgICAgICAgICAidG90YWxQcmljZSI6IDc1LjAKICAgICAgICB9CiAgICBdLAogICAgInRvdGFsQW1vdW50IjogMTc1LjAsCiAgICAiY3VycmVuY3kiOiAiVVNEIgp9'))

Step 3

Run our flow to see the JSON