In this “Parse JSON in Power Automate” article, we will learn how to parse JSON in Power Automate with examples. Power Automate is a powerful tool that allows you to automate workflows and integrate various applications and services. One common task in workflow automation is handling JSON (JavaScript Object Notation) data. JSON is a lightweight data-interchange format that is easy for humans to read and write and easy for machines to parse and generate.
In this article, we will discuss how to parse JSON data effectively within Power Automate, enabling you to extract the information you need from JSON responses or files and utilize it in your workflows.
Learn How To Parse JSON in Power Automate
Before getting into the demo on how to parse JSON in Power Automate, let us understand the basic concept of JSON objects.
Understanding JSON: What is JSON?
JSON is a text-based data format that represents structured data using key-value pairs. It is widely used to transmit data between a server and a web application as an alternative to XML. JSON objects are encapsulated in curly braces {} and consist of key-value pairs, where keys are strings and values can be various data types such as strings, numbers, arrays, or nested objects.
Here’s a simple example of a JSON object:
{ "name": "John Doe", "age": 30, "isStudent": false, "hobbies": ["reading", "cooking", "traveling"], "address": { "street": "123 Main St", "city": "Anytown", "state": "CA" } }
Why do we parse JSON Data?
Parsing JSON data is a crucial step in software development, especially when working with web APIs (Application Programming Interfaces) and data interchange. JSON (JavaScript Object Notation) is a lightweight, human-readable data format that is commonly used to transmit and store structured data. Parsing JSON data involves converting a JSON string into a usable data structure within a programming language.
Here are several reasons why parsing JSON data is important:
- Data Extraction and Access: JSON data often contains structured information such as key-value pairs, arrays, and nested objects. Parsing allows developers to extract and access specific pieces of data by navigating the JSON structure, making it usable within their applications.
- Data Processing: Once JSON data is parsed, developers can manipulate and process the extracted data based on the application’s requirements. This might involve performing calculations, filtering, or transforming the data in some way.
- Integration and Interoperability: Many web services and APIs return data in JSON format. By parsing JSON responses, developers can integrate this data seamlessly into their applications, enabling interoperability and allowing different systems to communicate and exchange information.
- Error Handling: During the parsing process, error handling mechanisms can be implemented to handle malformed or incorrect JSON data. This ensures the application gracefully manages unexpected data and prevents potential crashes.
- Data Serialization: In addition to parsing, JSON is used for serializing data from objects in programming languages to a JSON format. This is crucial for sending data to APIs or storing it in a persistent manner, like saving it to a file or a database.
- Interacting with APIs: APIs often provide data in JSON format due to its lightweight and easily readable structure. By parsing this JSON data, applications can interpret the response and use the data effectively to display information to users or perform specific actions based on the API’s response.
- Cross-Platform Communication: JSON is language-independent, making it an excellent choice for data interchange between different platforms and programming languages. Parsing JSON allows applications written in different languages to communicate and understand the shared data format.
- Configuration and Settings: JSON is also used for storing configuration settings in applications. Parsing the configuration JSON allows applications to read and utilize these settings to configure various aspects of the application dynamically.
Parsing JSON data is a fundamental skill for developers as it enables them to work with data in a structured, efficient, and standardized manner, facilitating seamless communication, data processing, and integration between different systems and services.
In other words, when we retrieve data from an API or any other programming language from the data source or application, the data we receive is not in a structured or human-readable format; to make it human-readable or structured, we should parse the JSON data.
Exploring JSON Parsing: Understanding the Transformation of Raw Data to Usable Structures
In the realm of data processing and integration, JSON (JavaScript Object Notation) serves as a prevalent format for transmitting and storing structured data. However, raw JSON data is not easily digestible by humans. This section explains the fundamental concept of JSON parsing, shedding light on how it facilitates the transformation of unwieldy raw JSON data into structured and user-friendly formats, enabling seamless data utilization and interpretation within software applications.
Following are the few points we should know about parsing the JSON data:
- Parsing JSON Simplified: The process of parsing JSON involves taking the initial raw and less human-readable JSON data and transforming it into a structured, easily understandable format. Given our human limitations in interpreting raw data, parsing becomes essential, acting as a bridge to present the JSON data in a user-friendly layout. In essence, it’s a technical term denoting the conversion of raw data into a neatly structured and readable display.
- Breaking Down JSON: To parse JSON is to effectively break down the initial unrefined JSON data, making it manageable and comprehensible by segregating it into meaningful parts.
- Deconstructing the JSON String: Upon receiving JSON data, it arrives as a massive string, a fusion of characters. Concealed within this string are encoded tags and “name: value” pairs. The parser’s role is to dissect this extensive string and organize it into the specified data structures, often represented as objects in the string.
- JSON Encoding vs. Parsing: JSON encoding involves the process of creating a JSON string from data structures, whereas parsing JSON is the inverse process, involving the breakdown of a JSON string into its respective data structures.
Demo: Parsing JSON in Power Automate
Power Automate provides built-in actions and expressions to easily parse and work with JSON data. Here’s a step-by-step guide on how to parse JSON in Power Automate:
Example 1: Parse JSON in Power Automate with static data
Let’s create a manually triggered flow, or you can use your existing test flow for this demo.
Create an object-type variable and pass the below text in the value box:
{ "name": "John Doe", "age": 30, "isStudent": false, "hobbies": ["reading", "cooking", "traveling"], "address": { "street": "123 Main St", "city": "Anytown", "state": "CA" } }
Run the flow, copy the below value, and paste it in a notepad.
{ "name": "John Doe", "age": 30, "isStudent": false, "hobbies": [ "reading", "cooking", "traveling" ], "address": { "street": "123 Main St", "city": "Anytown", "state": "CA" } }
Add a “Parse JSON” data operation action.
Configure the below in the “Parse JSON” action:
- Content: Select “varSampleJSON” from the Dynamic Content Variables section.
- Schema: Click on the “Generate from sample” button.
Once you click on the “Generate from sample” button, you will get an option to insert a sample JSON payload screen.
Now, copy the sample JSON from your notepad where you have pasted in the above step and paste it into this box:
Click on the “Done” button.
We can see that a sample JSON schema was created. By the way, let’s understand what a JSON schema is.
What is JSON schema?
In simple terms, a JSON schema is the definition of your source data, meaning that in the above sample JSON, the type of the data is not defined. After creating the schema, we have the definition of each data point shown in the sample JSON.
In the context of the “Parse JSON” action in various platforms or programming environments, a schema in this context refers to a formalized structure or blueprint that defines the expected format of a JSON object. It outlines the arrangement of keys, their types, and any potential nesting or hierarchy within the JSON object.
When you’re parsing JSON using the “Parse JSON” action, providing a schema helps the parsing mechanism understand the structure of the incoming JSON data. The schema acts as a guide, allowing the parser to interpret the JSON data correctly and map it to appropriate data types in the programming environment.
The schema typically includes information such as:
- Key Names and Types: It specifies the keys present in the JSON object and their respective data types, such as string, number, boolean, array, or nested object.
- Array Structure: If the JSON object contains arrays, the schema defines the structure and data types of elements within those arrays.
- Nested Objects: If the JSON object contains nested objects, the schema defines their structure and the keys they contain.
Providing a schema is crucial for accurate parsing. It ensures that the parsed data is in a format that aligns with your application’s expectations, enabling seamless integration and utilization of the parsed data within your workflow or application. It helps maintain data consistency and reliability when working with JSON data.
How do you understand that your source data is in JSON format?
It is very simple to identify that the source data is in JSON format. Let’s have a close look at the below data:
If we notice the above content—curly braces, property name, value, etc.—is in a different color format, that means this data is in JSON format.
Let’s validate this statement and what we said here.
Now, let’s change the data type of “varSampleJSON” from object to string and run the flow.
Now, once we run the flow and see the Parse JSON action content, we can see that the data is no longer in color format; now it is in plain text format, which is not JSON.
Disclaimer:
- In the above example, even though we say that this is not JSON format, it is plain text. That doesn’t mean the “Parse JSON” action cannot parse this plain text, no matter whether the data is in JSON formatted color or in plain text, until it has valid schema and content in JSON syntax. action parse it. Our intention here was just to show how we can say whether the data is JSON formatted or not just by looking at it.
Example 2: Parse JSON in Power Automate with dynamic data (SharePoint Online List or Document Library)
In the above demo, we have seen how to parse a sample JSON data. Now, let’s think about complex JSON data, for example, data from a SharePoint Online list or document library, and how to parse it.
To do this, you can add either Get Items or Get Files (Properties Only) or any get action from the SharePoint list or document library. Here we have used the “Get Files (Properties Only)” action.
Note:
- Here we are showing the flow in run mode; the configuration part is not shown as it is straightforward.
Click on the “Click to download” link. Then, you can see something like the below JSON.
Copy this entire text and paste it into Notepad or any text editor.
Add a “Parse JSON” data operation action.
In the content, select body from the “Get files (properties only)” dynamic content tab.
Like in the previous demo, click on the “Generate from sample” button.
In the “Insert a sample JSON Payload” box, paste the entire Get files (properties only) output from your notepad.
Click on the “Done” button.
Now, we can see a valid JSON schema for SharePoint Online. Get files (properties only) action; that’s it done.
You can play around with this JSON data and use it to further your business logic. We can notice that from the Dynamic Content tab, under the “Parse JSON 2” section, we can see each JSON property separately, and we can use them for further business needs in our flow development.
Summary: Parse JSON in Power Automate
Thus, in this article, we have learned about how to parse JSON in Power Automate and the following concepts of JSON in Power Automate:
- What is a JSON file?
- What is schema in Power Automate?
- How to construct a sample JSON file
- How to parse a sample JSON file
- How to parse complex JSON data like SharePoint Online lists or document library data
- Why should we parse JSON data?
See Also: Other Power Platform Articles
You may also like the following Power Platform articles:
- Power Automate: Get All Flows in Environment – List of All Flows In The Environment
- Security Roles and Groups in Power Platform Environment
- Power Platform Environment Limitations: What You Need to Know
- Overview of Solutions in Power Platform Environment: Create Step By Step
- Sandbox vs Production Environment in Power Platform: Unleashing the Power of Choice
- In just 2 steps quickly export import power automate flow
- PowerApps Development Environment: Create free development environment using Power Apps Community Plan
- Take care of what’s important. Automate the rest.