SharePoint List Form JSON Formatting Examples

SharePoint list forms are a powerful way to manage and interact with data within your SharePoint environment. With JSON formatting, you can take this power to the next level by customizing the appearance and behavior of your list forms. In this article, we'll explore various SharePoint list form JSON formatting examples to help you unlock the full potential of this feature.

Customize SharePoint Forms with JSON
Customize SharePoint Forms with JSON

Before we dive into the examples, let's briefly understand what JSON formatting is. JSON (JavaScript Object Notation) is a lightweight data interchange format that is easy for humans to read and write and easy for machines to parse and generate. In the context of SharePoint, JSON formatting allows you to apply conditional styles, hide or show columns, and even add custom functionality to your list forms.

Display SharePoint List Items in a SPFX Web Part [Tabular Format]
Display SharePoint List Items in a SPFX Web Part [Tabular Format]

Basic JSON Formatting

Let's start with the basics. The foundation of JSON formatting is the JSON object, which consists of key-value pairs. In SharePoint, these keys correspond to different elements of your list form, such as 'FieldName' for the name of a column, 'DisplayName' for the column header, and 'Value' for the cell content.

How to customize Forms in SharePoint Lists 📃
How to customize Forms in SharePoint Lists 📃

Here's a simple example that changes the background color of a cell based on the value of a 'Status' column:

```json { "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "span", "style": { "background-color": "=if([$Status] == 'Completed', '#D1F1E0', '#FFF')" } } ```

Conditional Formatting

Customizing SharePoint List Forms in InfoPath 2010
Customizing SharePoint List Forms in InfoPath 2010

Conditional formatting is one of the most common use cases for JSON formatting. It allows you to apply different styles based on the value of a column. In the example above, we used an 'if' statement to change the background color based on the 'Status' column.

You can also use 'if' statements to show or hide columns. Here's an example that hides the 'Due Date' column if the 'Status' is 'Completed':

```json { "elmType": "span", "style": { "display": "=if([$Status] == 'Completed', 'none', 'block')" } } ```

Custom Functionality

Add Conditional Formatting to a SharePoint Online List
Add Conditional Formatting to a SharePoint Online List

JSON formatting also allows you to add custom functionality to your list forms. For example, you can use the 'executeJavaScript' function to run custom scripts. Here's an example that displays a confirmation dialog when a user tries to delete an item:

```json { "elmType": "span", "txtContent": "Delete", "style": { "cursor": "pointer" }, "customActions": { "onClick": { "command": "executeJavaScript", "parameters": { "script": "if(!confirm('Are you sure you want to delete this item?')){return false;}" } } } } ```

Advanced JSON Formatting

While the examples above demonstrate the basics of JSON formatting, SharePoint also supports more advanced features. For instance, you can use 'applyToAll' to apply formatting to all columns in a row, and you can use 'transform' to manipulate the data before it's displayed.

How to List Unique Permissions for Files and Folders on a SharePoint Site
How to List Unique Permissions for Files and Folders on a SharePoint Site

Here's an example that applies a strike-through style to all columns in a row if the 'Status' is 'Cancelled':

```json { "elmType": "tr", "style": { "text-decoration": "=if([$Status] == 'Cancelled', 'line-through', 'none')" }, "applyToAll": true } ```

Using JSON Formatting with Modern Experience

Flow that Adds Forms Results to SharePoint
Flow that Adds Forms Results to SharePoint
SharePoint Page Section Templates Explained
SharePoint Page Section Templates Explained
Learn How To Implement Sharepoint List Validation
Learn How To Implement Sharepoint List Validation
How to implement Document Management System in SharePoint using Content Types | SharePoint Maven
How to implement Document Management System in SharePoint using Content Types | SharePoint Maven
How to Create a Custom List in SharePoint | Beginner Tutorial
How to Create a Custom List in SharePoint | Beginner Tutorial
How to track documents in SharePoint using Document ID feature | SharePoint Maven
How to track documents in SharePoint using Document ID feature | SharePoint Maven
Why You Should Never Embed Document Libraries and Lists into SharePoint Pages
Why You Should Never Embed Document Libraries and Lists into SharePoint Pages
Editing a Form: InfoPath
Editing a Form: InfoPath
SharePoint Content Types - BoostSolutions
SharePoint Content Types - BoostSolutions
📊 How to create Charts in Microsoft SharePoint Lists
📊 How to create Charts in Microsoft SharePoint Lists
How to Create a Custom Permission Level in SharePoint
How to Create a Custom Permission Level in SharePoint
Site Collections, Sites, Pages, Document Libraries, and Folders - putting it all together | SharePoint Maven
Site Collections, Sites, Pages, Document Libraries, and Folders - putting it all together | SharePoint Maven
How to create Hub Sites in SharePoint | SharePoint Maven
How to create Hub Sites in SharePoint | SharePoint Maven
How To Create A Page In SharePoint: A Step-By-Step Guide
How To Create A Page In SharePoint: A Step-By-Step Guide
SharePoint Tutorial #2 - SharePoint Document Library
SharePoint Tutorial #2 - SharePoint Document Library
Client Challenge
Client Challenge
How to Personalize SharePoint for Users
How to Personalize SharePoint for Users
How to Get Started with SharePoint Look Book
How to Get Started with SharePoint Look Book
the shareholders agreement is shown in this document, which includes two separate sections and one section
the shareholders agreement is shown in this document, which includes two separate sections and one section
ServiceNow Client Scripts
ServiceNow Client Scripts

JSON formatting is fully supported in the modern experience of SharePoint. In fact, many of the out-of-the-box formatting options in modern experience are powered by JSON. Here's an example that changes the icon of a 'Choice' column based on the selected option:

```json { "elmType": "span", "style": { "padding-left": "20px" }, "txtContent": "=if([$Status] == 'Active', '🟢', if([$Status] == 'Inactive', '🔴', '🟡'))" } ```

JSON Formatting with Power Apps

JSON formatting can also be used in conjunction with Power Apps to create even more complex and interactive list forms. For example, you can use JSON formatting to conditionally show or hide fields based on user input in a Power App.

Here's a simple example that hides the 'Notes' field if the 'Priority' is 'Low':

```json { "elmType": "div", "style": { "display": "=if([$Priority] == 'Low', 'none', 'block')" } } ```

In conclusion, JSON formatting opens up a world of possibilities for customizing your SharePoint list forms. Whether you're looking to add a simple visual touch or build complex, interactive experiences, JSON formatting has you covered. So, start exploring and see what you can create!