SharePoint Online modern list column formatting using JSON

This SharePoint tutorial, we will discuss SharePoint Online modern list column formatting using JSON in SharePoint Online modern lists and libraries.

SharePoint Online modern list column formatting

We use column formatting to customize how fields in SharePoint lists and libraries are displayed.

SharePoint Online Column formatting is easier to use and an OOTB resolution to the problem statement. However, it is less flexible because it does not allow custom code solutions, it only allows for certain predefined elements, classes, and attributes.

In SharePoint online Column formatting users can easily find list item value to change styling based on conditions, such as applying different colors on item value, placing indicator icon, formatting data in a bar chart, etc.

Column formatting works with JSON structure, below are the common nodes in JSON used to change styling and branding of list item values.

Common Nodes in JSON

  • elmType – Specifies the element type like DIV, span, A
  • debugMode – An optional property that is meant for debugging
  • attributes – An optional property that specifies additional attributes to add to the element
  • class – Specifies the predefined class for style and action
  • operator – Specify the type of operation to perform like =, -, +, <, >, <=, etc…
  • operands – Specifies the parameters or operands for an expression

The user has created the “ICC world cup Team Modern SharePoint List”. In the list, an item of specific column value is showing the Country-wise flag icon without code formatting the column content.

We achieve the expected result using SharePoint online new feature Column formatting list item value of specific Column Using JSON.

Apply Column Formatting in a Specific Column in SharePoint

Navigate to your SharePoint Online site -> open SharePoint list -> Follow the numerical point as shown in the below screenshot.

sharepoint online list column formatting

JSON Code 

{  
	  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",  
	  "elmType": "div",  
	  "children": [  
	    {  
	      "elmType": "img",  
	      "attributes": {  
	        "src": "='https://flagpedia.net/data/flags/h20/'+if(@currentField == 'Afghanistan','af',if(@currentField == 'West Indies','jm',if(@currentField == 'Sri Lanka','lk',if(@currentField == 'South Africa','za',if(@currentField == 'Pakistan','pk',if(@currentField == 'New Zealand','nz',if(@currentField == 'India','in',if(@currentField == 'England','gb',if(@currentField == 'Bangladesh','bd',if(@currentField == 'Australia','au','in'))))))))))+ '.png'",  
	        "title": "=if(@currentField == 'Afghanistan','Afghanistan',if(@currentField == 'West Indies','West Indies',if(@currentField == 'Sri Lanka','Sri Lanka',if(@currentField == 'South Africa','South Africa',if(@currentField == 'Pakistan','Pakistan',if(@currentField == 'New Zealand','New Zealand',if(@currentField == 'India','India',if(@currentField == 'England','England',if(@currentField == 'Bangladesh','Bangladesh',if(@currentField == 'Australia','Australia','India'))))))))))"  
	      }  
	    }  
	  ]  
	}  

After adding the JSON and clicking the save button then we see the preview output of the result.

Get the flag codes table. To do so, copy & paste this whole table with the flag codes from Github.

Once you apply column formatting using JSON, you can see the result like below:

Before applying the column formatting Screen

sharepoint modern list column formatting

After applying the column formatting Screen

sharepoint modern list column formatting example

Limitations and Predefined OOTB Classes

Supported column types

Sr.NoSupported Column Format ListUn- Supported Column Format List
1.Single line of textManaged Metadata
2.NumberFilename (in Document Libraries)
3.ChoiceCalculated
4.Person or GroupRetention Label
5.Yes/NoCurrency
6.HyperlinkManaged Metadata
7.PictureFilename (in Document Libraries)
8.Date/Time 
9.Lookup 
10.Title (in Lists) 

Currently Available OOTB Predefined classes

sharepoint modern list column formatting

For more details, please refer to this link.

You may like following SharePoint tutorials:

This SharePoint tutorial, we discussed SharePoint Online modern list column formatting using JSON.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>