Mastering JSON Formatting in SharePoint: Substring Magic
In the dynamic world of SharePoint, JSON (JavaScript Object Notation) formatting has become an indispensable tool for customizing and enhancing list views. One powerful aspect of JSON formatting is its ability to manipulate substrings, allowing you to display data precisely as needed. Let's delve into the world of SharePoint JSON formatting substring manipulation.
Understanding JSON Formatting in SharePoint
JSON formatting in SharePoint enables you to transform the way list views appear, making them more intuitive and engaging. It's a powerful alternative to traditional SharePoint styles, offering a high degree of customization. JSON formatting uses a JSON object to define the appearance of list items, including text, colors, icons, and more.
What is a Substring?
A substring is a sequence of characters within a string. In the context of SharePoint JSON formatting, substrings allow you to extract, replace, or manipulate specific parts of text. For instance, you might want to display only the first few words of a long text, or replace certain characters with others.

JSON Formatting Substring Functions
SharePoint JSON formatting offers several functions to work with substrings. Here are a few key ones:
- substring(): Extracts a substring from a string. Syntax:
substring(startIndex, length). - replace(): Replaces a substring with another string. Syntax:
replace(find, replace). - toUpper() and toLower(): Convert a string to uppercase or lowercase, respectively.
Practical Examples
Let's explore some practical examples of how these functions can be used in SharePoint JSON formatting.
Displaying Only the First Few Words
To display only the first few words of a long text, you can use the substring() function. For example, to display the first 20 characters of the 'Title' column:

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"additionalRowClass": "sp-field-severity--high",
"columnValues": {
"Title": {
"operator": "substring",
"operands": [0, 20]
}
}
}
Replacing Characters
You can use the replace() function to replace certain characters. For instance, to replace all hyphens (-) with spaces in the 'Title' column:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"additionalRowClass": "sp-field-severity--high",
"columnValues": {
"Title": {
"operator": "replace",
"operands": ["-", " "]
}
}
}
Best Practices and Limitations
While JSON formatting substring manipulation offers a wealth of possibilities, it's important to keep a few things in mind:
- JSON formatting is not supported in all SharePoint views. It's best to test your formatting in different views to ensure it works as expected.
- Be mindful of performance. While JSON formatting is powerful, it can also slow down your site if not used judiciously.
- Consider accessibility. Ensure that your formatting doesn't negatively impact users with disabilities.
Conclusion
Mastering JSON formatting substring manipulation in SharePoint opens up a world of possibilities for customizing and enhancing your list views. Whether you're displaying only the first few words of a text, replacing characters, or performing other manipulations, the power of substrings in JSON formatting is a tool no SharePoint power user should be without.



![Display SharePoint List Items in a SPFX Web Part [Tabular Format]](https://i.pinimg.com/originals/ef/45/21/ef45215299f094b62fbf5fd9eee232aa.jpg)



















