sharepointsharepoint-onlinesitetemplate

"ø" showing instead of "ø" and more


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.sstatic.net/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.


Solution

  • 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.