You can find a JSON library in your language that you can feed some appropriate data structure to, and let it work for you.
In JSON the only characters you must escape are \, ", and control codes. Thus in order to escape your structure, you'll need a JSON specific function. As you might know, all of the escapes can be written as \uXXXX where XXXX is the UTF-16 code unit¹ for that character.
Hope this helps!