0

We use a site script to apply site templates in SharePoint online. Recently, it has seemed as though some characters are displaying on the site differently than in the JSON template file.

A sample portion from the site script template:

{
      "verb": "addSPView",
      "name": "Aktive leverandører",
      "viewFields": [
        "UID",
        "LinkTitle",
        "Link",
        "Active",
        "ApprovedSupplier",
        "Classification",
        "InternalResponsible",
        "Website",
        "Created"
      ],
      "query": "<OrderBy><FieldRef Name=\"Created\" Ascending=\"FALSE\" /></OrderBy>",
      "rowLimit": 30,
      "isPaged": true,
      "formatterJSON": "{\"additionalRowClass\":{\"operator\":\":\",\"operands\":[{\"operator\":\"==\",\"operands\":[{\"operator\":\"%\",\"operands\":[\"@rowIndex\",2]},0]},\"sp-css-backgroundColor-neutralBackground\",{\"operator\":\":\",\"operands\":[{\"operator\":\"==\",\"operands\":[{\"operator\":\"%\",\"operands\":[\"@rowIndex\",2]},1]},\"sp-css-backgroundColor-noFill\",\"\"]}]},\"rowClassTemplateId\":\"BgColorAlternateRows\"}",
      "replaceViewFields": true
    }

What is shown on the site: (https://i.stack.imgur.com/Q9y34.png)

There are few other characters are also shown like this.

The website should display the same character as the JSON file has. Any help would be appreciated.

Steve B
  • 36,818
  • 21
  • 101
  • 174
Shafeeq
  • 21
  • 5
  • Probalby the json file is not utf8 encoded... How to you deploy the site script ? – Steve B Jul 18 '23 at 13:04
  • We are using PowerShell commands to apply the site template $CRMHubAllLists = Get-Content -Path "" | Out-String $crmhuballlistssitescript = add-spositescript -title "" -content $CRMHubAllLists -description "" $crmhuballlistssitedesign = add-spositedesign -title "" -webtemplate "68" -sitescripts $crmhuballlistssitescript.id -description "" Add-SPOSiteDesignTask -SiteDesignId – Shafeeq Jul 18 '23 at 13:22
  • I guess the variable `$CRMHubAllLists` already contains the invalid chars. How are you populating this variable ? If it loaded from a file, ensure both file is utf8 encoded and you load the using the proper encoding – Steve B Jul 18 '23 at 13:24
  • The variable is loaded from a JSON file exported from another SharePoint site. and Notepad++ shows it is UTF-8 encoded. Just checked changing the variable but no luck. – Shafeeq Jul 18 '23 at 13:49
  • Then, can you ensure you load the JSON file as UTF8 explicitely ? `$sitescript = Get-Content -LiteralPath "somescript.json" -encoding utf8`. The powershell default is not utf8, but local codepage (at least in my French version of windows) – Steve B Jul 19 '23 at 06:52
  • @SteveB Yes, that worked. loading the JSON file as UTF8 explicitly did the trick. – Shafeeq Jul 19 '23 at 09:25

1 Answers1

0

Most of time, having weird characters in place of some non english letters, or letters with diacritics are related to incorrect alignment of encoding.

Most of time, strings are encoded using utf8 to deal with international characters. Letters can take either 1 or 2 bytes to represent the character.

If you read the bytes using an ascii decode, the two bytes will be read as separated chars, instead of a single 2 bytes one.

Regarding the comments on the question, it seems that your JSON file which contains the site script is OK (you saw proper chars and notepad reported it as UTF8 encoded).

However, when you was reading the file, you probably didn't specify the encoding. Powershell will use the default codepage of the system when reading the file.

In order to solve your issue, you can ensure the proper encoding is used:

$sitescript = Get-Content -LiteralPath "somescript.json" -encoding utf8

This way, the variable will be properly read.

Steve B
  • 36,818
  • 21
  • 101
  • 174