top of page

What is JSON and Why Should Power Platform Developers Understand It?

If you've gotten into the technical weeds of the Power Platform, particularly Power Automate, you've probably run into JSON (pronounced J-Sonn, Jason, or J'son in an exquisite French accent depending on who you ask). While it might sound technical, it's fairly straightforward once you format it and break down the components.

Why JSON Matters

JSON's significance in the Power Platform (really all app development) cannot be overstated. It has become the primary language of web APIs and web services, bridging the gap between servers and clients. In scenarios where data needs to be transferred, stored, or displayed, JSON emerges as the go-to format. Its lightweight nature speeds up data transactions, enhancing the performance of web applications. It will no doubt come up in many areas of the Power Platform, such as:

  1. Power Automate

    1. Troubleshooting - while combing through a failed flow, you'll no doubt be given some JSON object that contains information about an action. Nearly every action in Power Automate is an abstraction of an API call that is configured to receive and send JSON payloads. Even the error messages returned from these calls are JSON. Being able to understand the structure of these payloads is crucial in trying to figure out where something went wrong.

    2. APIs - As I said above, Power Automate is mostly an interface for sequencing API calls abstracted into a no-code UI. APIs are EVERYWHERE and chances are most of the web apps you use have one. APIs (application programming interface) are interfaces that allow developers to interact with different software applications, often including the ability to perform CRUD operations on data programmatically. Custom connectors, for example, are built by configuring an API in preparation for it to be accessible in the Power Automate interface. It takes a moderate understanding of JSON (in most cases, not all APIs use JSON) to be able to configure a custom connector or leverage an API.

    3. HTTP Trigger - While not a requirement for this trigger, using JSON in an HTTP trigger by receiving a JSON payload and sending back a JSON response enables you to extend your data to external customers by offering a quasi-API experience, allowing data access without the need to configure a full API in services like Azure APIM.

  2. Power Apps

    1. Canvas Apps

      1. ParseJSON - The ParseJSON function allows you to use raw JSON strings in a canvas app to extract untyped values from the object. For example, I've built an app where inventory is tagged with a QR code sticker which itself held a JSON string. That JSON string contained all of the information about that product and a quick scan along with the ParseJSON function allowed me to display the data within the app without using any Power Automate.

      2. Flow Payload - As mentioned above, once a collection is JSON-ified using the ParseJSON function, it can easily be sent to Power Automate as a single JSON payload that can then be parsed and used in a flow.

    2. Model-Driven Apps

      1. Javascript - Although a minimal and more pro-dev side of the Power Platform we can't talk about JSON without mentioning the JS that gives it its name. Using JavaScript to extend the functionality of a Model-Driven App gives you a whole new set of flexibility in an otherwise rigid app design. JavaScript can do everything from show/hide form fields and sections to call APIs and set field values. It's a must if the out-of-the-box UI functionality from business rules or form configuration doesn't cut it.

These are all advanced topics within the Power Platform and will be covered in separate blog posts down the road. Beyond all of these reasons, learning JSON can be a gateway from citizen developer to more pro-dev skills! It's a crucial step toward learning and getting more comfortable with the structure and standards that make the Internet work. Now let's get into the details of how JSON is structured and what all those symbols mean.


What is JSON?

JSON, or JavaScript Object Notation, is a text-based data format used predominantly for data interchange in web applications. JSON uses symbols to structure data

  • {Curly Braces}: Used to enclose objects. An object begins with { (left brace) and ends with } (right brace). Inside the braces, there is a list of properties (key-value pairs) separated by commas.

  • [Square Brackets]: Used to enclose arrays or a list of objects. An array begins with [ (left bracket) and ends with ] (right bracket). Inside the brackets, values are listed and separated by commas.

  • "Double Quotes": Used to enclose strings. Both keys and string values in JSON are enclosed in double quotes.

  • Colon ( : ): Used to separate keys (the name of a property) from their values in objects.

  • Comma ( , ): Used to separate pairs of items, like properties in an object or elements in an array.


JSON supports various data types, which are inferred from the format of the data itself.

  • Strings: Strings are expressed as a value within quotation marks

    • Example: "Hello, World!"

  • Boolean (True/False): Boolean values are expressed as the words true or false without quotations and are case-sensitive. The two valid boolean values are true and false.

    • Example: true

  • Number: Numbers can be represented in JSON as integers or floating-point values. While JSON does not impose specific limits on number values, it's essential to consider the environment in which the JSON is processed. Extremely large or precise numbers might require careful handling, such as representing them as strings, to ensure accuracy and compatibility across different systems.

    • Examples

      • 3.14

      • 100

      • -30

  • Null: Null is used to represent the absence of a value. Like boolean values, it is a case-sensitive string without quotations.

    • Example: null


The Structure of JSON

A JSON object contains key-value pairs. You can think of this like a dictionary that contains a word (the key) along with that word's definition (the key's value). The syntax is fairly simple: it begins and ends with curly braces {}, with each key-value pair separated by a comma. The keys (always strings) are enclosed in double quotes, while values can be strings, numbers, arrays, booleans, null, or other nested JSON objects. Let's make a simple JSON object of a key called user with a single value that represents its ID, which is 1.


{
	"user": 1
}

In this example, we have our outer curly braces with a user property indicated by the user key (surrounded by quotes as all keys are regardless of type), and a numeric value of 1. The lack of quotes around the 1 means this is an integer, not a string. We don't have to state the data types explicitly because they are implied directly in the object.

What if we want to give our user a name? Well, we simply make the user key a nested object within the parent object with a comma-separated list of properties, like this:


{
	"user":
		{
			"id": 1,
			"name": "John"
		}
}

Now, instead of the user property being a reference to its id of 1, it has become an object with an id and name property, all contained in the original outer constructor curly braces. What if we want to represent multiple users in one object, though? For that, we'll use the square brackets with a comma-separated list (called an array) of user objects, like this:


{
	"users":
		[
			{
				"id": 1,
				"name": "John"
			},
			{
				"id": 2,
				"name": "Jane"
			}
		]
}

Example of JSON

Let's illustrate with a more detailed JSON object:



{
    "user": {
        "name": "Eric",
        "age": 30,
        "isDeveloper": true,
        "contact": {
            "email": "eric@example.com",
            "phone": "123-456-7890"
        },
        "languages": [
            "JavaScript",
            "Python",
            "Java"
        ],
        "projects": [
            {
                "name": "WebApp",
                "language": "JavaScript"
            },
            {
                "name": "DataAnalysis",
                "language": "Python"
            }
        ]
    },
    "departments": [
        "IT",
        "HR",
        "EXC",
        "FIN",
        "MNT",
        "CR",
        "SAL"
    ]
}

In this example, you can see nested objects (contact and projects) and an array of objects, showcasing JSON's ability to represent complex data structures. We also have a second object after the user object that lists department codes. There is no limit to the number of sub-objects a JSON object can contain.


The structure of a JSON object can be described by a schema, which is itself a JSON object that defines the expected format of the JSON data. The schema defines valid key-value pairs and gives the developer and the application a full view of the objects and fields that are available in an incoming JSON object without the need for the object itself. For example, the JSON object


{
	"name": "Eric Lott",
	"age": 30,
  	"occupation":{
     	"title": "Power Platform Architect",
		"yoe": 6
    }
}

has a schema of


{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "age": {
      "type": "integer"
    },
    "occupation": {
      "type": "object",
      "properties": {
        "title": {
          "type": "string"
        },
        "yoe": {
          "type": "integer"
        }
      },
      "required": [
        "title",
        "yoe"
      ]
    }
  },
  "required": [
    "name",
    "age",
    "occupation"
  ]
}

Note that it outlines the key names, the value data types as well as which fields are required.

A JSON schema is used not only to outline the structure but also to validate the JSON data against the defined structure, ensuring it meets the required format and types.


With this understanding, you should be able to read and write JSON objects to fit your data needs! JSON is usually presented in an unformatted text block, but there are many JSON formatting tools out there as well as validators for when you are creating a JSON object. Here are the links to my favorite ones:

955 views0 comments

Comments


bottom of page