It *should* have a JSON body, but in this particular case I can't be sure that it will, as I'm trying to log requests when there are errors, which are quite often errors in the request. So although in some cases it is decoded later in the handler chain, I need to be able to log the string in a human readable form before any possible decoding.
If it's unescaped as part of json.Unmarshal(), is there an exposed function in the encoding/json package which only unescapes a string? I've tried looking, but I can't find anything that I can call directly. On Sunday, 25 December 2016 06:14:22 UTC+1, Matt Harden wrote: > > If it has a JSON body, are you using encoding/json to parse / decode it? > That will handle the unescaping for you. > > On Sat, Dec 24, 2016 at 4:54 PM JohnGB <jgbe...@gmail.com <javascript:>> > wrote: > >> I have an application where I am processing a HTTP request with a JSON >> body. However, the JSON in the body has been unicode escaped, so instead >> of `wasn't`, I get `wasn\u0027t`. >> >> What is the simplest way to unescape this text back to utf8 encoded text. >> i.e. convert `wasn\u0027t` to `wasn't`. Please note that I'm only using >> this as an example, but I'd like all unicode escaped characters to be >> converted to their utf8 equivalents. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.