SharePoint JSON Formatting – “Name cannot begin with the ‘=’ character”

Have you ever tried to apply column formatting to your SharePoint list views using code? If so, it’s likely you have come across this error and unfortunately there isn’t much information in the documentation on how the JSON Formatter string should be formatted.  Take for example this scenario:

Updating a view format using PnP PowerShell

PnP PowerShell has functionality for setting properties of a view using the command Set-PnPView

Updating the formatting on your list is done by passing in a JSON string to your Set-PnPView command using the CustomFormatter value property.

Set-PnPView -List "MyList" -Identity "MyViewName" -Values @{CustomFormatter = @'my-json-formatted-string'@}

Example JSON

Below is a basic example of applying a background color to a row on a view when the DueDate is less than now (date time).

{"schema":"https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json","additionalRowClass": "=if([$DueDate] <= @now, 'sp-field-severity--severeWarning', '')"}

Applying this format using PnP PowerShell

To apply this JSON script, you would use the following command

Set-PnPView -List "MyList" -Identity "MyViewName" -Values @{CustomFormatter = @'
{"schema":"https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json","additionalRowClass": "=if([$DueDate] <= @now, 'sp-field-severity--severeWarning', '')"}
'@
}

Running this command, you will likely receive the following error: Set-PnPView : Name cannot begin with the ‘=’ character, hexadecimal value 0x3D.

The Fix:

The reason you are seeing this error is because in the JSON itself you need to encode some of the values if you are using operators. What I mean by that is, if you are using &&, or operators in formulas such as “>=” or “<=“, you need to use their encoded values instead. In our example, we were using [$DueDate] <= @now. In order to apply this to our view, we need to encode “<=” into  “&lt;=” and the formula will work.

Below is the following command with a working JSON formatter value.

Set-PnPView -List "MyList" -Identity "MyViewName" -Values @{CustomFormatter = @'
{"schema":"https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json","additionalRowClass": "=if([$DueDate] &lt;= @now, 'sp-field-severity--severeWarning', '')"}
'@
}

 

Hope this helps you!