Decode UTF-8 characters from JSON file


#1

I have some JSON data with UTF-8 encoded sequences which look like:

[{
		"name": "Bj\u00c3\u00b6rn XYZe\u00c3\u009fle",
		"comment": "text & text"
	},
	{
		"name": "Simona XYZ",
		"comment": "bla citizens\u00e2\u0080\u0099 autonomy and text."
	}
]

In Hugo, I show this data with just {{ .name }}.

The problem: It doesn’t recode these UTF-8 sequences but shows them like this:

Björn XYZießle
bla citizens’ autonomy and text

Obviously, I lack a decoding function. I already tried safeHTML, safeJS or htmlUnescape. What can I do except changing the input data?


#2

I’d use markdownify:

{{ "bla citizens\u00e2\u0080\u0099 autonomy and text." | markdownify }}

Returns for me:

bla citizens’ autonomy and text. 

(Don’t know if that are the right characters, but they are at least not UTF-8 anymore. :slight_smile: )


#3

No, they’re not. The correct character would have been the backtick-apostrophe :wink:

As written above, it was an encoding error on the input side. However, maybe it would have been possible to decode this with Hugo or some additional Go magic.