Problem loading character ½ when using getJSON

Hi,

I have a partial template that successfully loads data from a JSON file using getJSON.
This is working fine but on some JSON files it fails to load the ½ character.

The JSON file is:

{
  "team" : "Team 2",
  "league" : ">> will my one half be loaded from JSON ½ data?<<",
  "full_results" : "/results/2017-18/team2/",
  "matches" :
  [
    {
      "date" : "",
      "opponent" : "Opp ABC",
      "venue" : "Away",
      "score" : "1 - 4",
      "result" : "Win",
      "report" : ""
    }
  ]
}

See the ½ character in the “league” entry above.

The partial template has code as shown:

{{.Content}}

{{ $json_data_filepath := path.Join "content" (path.Dir .Page.File) (.Params.json_data) }}
{{ $json_data := getJSON $json_data_filepath }}

<h2 id="league">½--{{$json_data.league}}--½</h2>
  • Loads any .Content on page being processed.
  • Forms path to json file and calls getJSON.
  • Then uses {{$json_data.league}} to fill h2 element.

This appears in browser as:



You can see that the ½ in {{$json_data.league}} is shown as black rhombus with a white question mark.
I have placed two ½’s in page Content and this is drawn correctly.
Also placed two ½’s in the template as ½-- and --½, both of which are shown correctly.

It appears to be limited to handling ½ from the getJSON loaded data {{$json_data.league}}.

Any ideas what I am doing wrong here?

  • I have tried running hugo server with --ignoreCache but no difference.
  • Fails only on one out of 27 JSON files.
  • It fails on all elements in the JSON file where I add a ½ (not just league)

I am running hugo version
hugo v0.89.4-AB01BA6E+extended windows/amd64 BuildDate=2021-11-17T08:24:09Z VendorInfo=gohugoio

Thanks,
Crawford.

The index.md file is:

---
title: "My title"
date: 2021-12-15T15:52:12Z
draft: false
author: First Surname
subtype: "league"
json_data: "2017_18.json"
---

Does this appear?
With a ½ is ok.
Must be problem when processing a ½ through json?

First of all check if all your files (including the JSON that you load from wherever) are encoded in UTF8. The questionmark in a square basically tells me that the browser is experiencing encoding issues with the content you supply.

There are htmlUnescape and htmlEscape but I am relatively sure that with proper encoding of all members in this issue the characters will be shown.

There are default charset tags in your HTML document too… set that always to utf8.

Also, what happens when you keep the >> and << out of that league string? Maybe some security templating functionality jumps into action assuming it’s HTML, in that case try safeHTML.

1 Like

This is an encoding error. It is unlikely that the error is due to the getJSON function

Try @davidsneighbour 's suggestions and let us know.

Issue solved.

The problematic JSON file(s) were in ANSI format rather than UTF-8.
Switching over to UTF-8 and it all works as expected.

Thanks for all your help!

Crawford.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.