SharePoint List View Formatting by JSON Using Lookup Value

Recently, while working on one of the client’s requirements, I encountered a problem adding the lookup column value to the JSON Code while formatting the SharePoint list. So, I thought I would share my experience in this blog post.

In this tutorial, I will explain how to add a lookup value to the SharePoint column formatting JSON background color. Also, I will describe how to add additional columns coming from a lookup column.

SharePoint Lookup Column Formatting using JSON Background Color

To explain this, I will represent the SharePoint list with a few columns, including the lookup column, as shown in the image below.

Column NameData Type
TitleSingle line of text (Default)
PredecessorsLook Up [Get information from Title]
Project Start DateDate and Time
Project End DateDate and Time
PriorityChoice
Sharepoint Look Up column formatting json background-color

Requirement: Here, I wanted to format the background color if the Title column value is equal to the Predecessors column value.

Follow the steps:

  1. In the SharePoint list, click on +Add view -> Provide View name -> Tap the Create button to add a new view. A new view of the SharePoint list has now been created.
Sharepoint List Look up column formatting json background-color
  1. To the newly created view [Look Up view] -> Click on the drop-down -> Select Format current view to open the Format view pane.
SharePoint json formatting lookup column
  1. Next, click the Advanced mode link in the Format view pane.
SharePoint column formatting based look up column
  1. Now, copy and paste the JSON code provided below, where we can format the list view background color for the items with the title ‘Predecessors’.

Important:

In the given code, replace the code with column internal names of your SharePoint list.

To add a lookup column, such as “Predecessors,” into a SharePoint list formatting, you need to provide it with .lookupValue [$Predecessors.lookupValue].

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "debugMode": true,
  "txtContent": "[$Predecessors]",
  "additionalRowClass": "=if([$Predecessors.lookupValue] == '[$Title]', 'sp-field-severity--severeWarning', '')"
}
Look up column formatting json background-color
  1. Then, click the Save button and close the pane. You can see the changes to your SharePoint list view, which is formatted with the background color.

Refer to the image below:

SharePoint List Formatting by JSON Using Lookup Value

Check out Customize SharePoint List Form Layout using JSON Code

Example 2: SharePoint List JSON Formatting with Lookup Column

In this example, I will demonstrate how to format the additional lookup column using JSON code.

Scenario:

Here, I wanted to format the Predecessors: Title, an additional column from Predecessors [Look Up]. Where, format the font color of the lookup column value, if the Predecessors Title column contains Evaluation as a value.

You can see that I have used the SharePoint list above to represent this example.

How to format SharePoint Look Up column using JSON

Steps to follow:

  1. On the SharePoint column header, choose Column settings ->click on Format this column.
SharePoint JSON formatting font color of Look Up column
  1. In the Format view pane, click on the Advanced mode link to insert the code.
SharePoint JSON format lookup column
  1. Then, add the json code provided below. Click on the Save button.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "debugMode": true,
  "txtContent": "[$Predecessors_x003a__x0020_Title]",
  "style": {
    "color": "=if([$Predecessors_x003a__x0020_Title] == 'Evaulation', '#FF0000', '#0000FF')"
  }
}
Using JSON Column Formatting SharePoint list

Output:

JSON Look Up Column Formatting in SharePoint

This is how to format a lookup column using JSON in SharePoint.

Conclusion

I hope that this tutorial has helped you understand how to add a lookup column to JSON code to format the SharePoint list view and learn how to format the SharePoint lookup column.

You may also like the following tutorials:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…