# User UTF-8 string in ConTeXt

I need to use input from a JSON inside my text. Sometimes it contains UTF-8 code. For example:

Belgi\u00e
cre\u00ebren


How can I use such string in ConTeXt LuaTeX, so the result is a correctly spelled Dutch word?

België
creëren


Preferably, as part of a sentence, where the %placeofbirthCandidate and %raisedinCountries are replaced by the content of the JSON.

\par Je bent geboren in %placeofbirthCandidate. Je bent opgegroeid in %raisedinCountries.

\par Je bent geboren in Belgi\"e. Je bent opgegroeid in Nederland, Belgi\"e en Engeland.

• note the javascript/JSON \u code is UTF-16 code points not UTF-8. Feb 11 '16 at 13:15
• Thanks, I will look into the matter and ask why they said UTF-8.
– SGL
Feb 11 '16 at 13:34

If you only need characters below \ua000 then you can presumably use

\def\u#1#2#3#4{\uchar"#1#2#3#4 }


If you need to use higher characters with a letter following \u then you could in addition make u a non-letter

\catcode\u=12


but best to do that in a local group or something will break.

(This is just using luatex primitives so should work in context.)

Note that characters between U+FFFF and U+10FFFF would be represented in JSON by two \u sequences denoting the UTF-16 encoding of the unicode value, so a complete solution would have to detect the first of a UTF-16 surrogate pair and combine with the following \u` code.

• Thank you very much. I will consult this with our team and start testing.
– SGL
Feb 11 '16 at 13:50