If you're processing anonymous messages and don't know where unicode will 
occur you might want something like 
this: https://play.golang.org/p/M-21sy_en5

On Monday, December 26, 2016 at 9:41:15 AM UTC-7, JohnGB wrote:
>
> Thanks Roger.  That is a really elegant solution.
>
> On 26 December 2016 at 17:32, roger peppe <rogp...@gmail.com <javascript:>
> > wrote:
>
>> On 26 December 2016 at 07:23, JohnGB <jgbe...@gmail.com <javascript:>> 
>> wrote:
>> > 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.
>>
>> If you've got a JSON string, then unmarshaling into a string should work.
>>
>> https://play.golang.org/p/AThEIUZnX4
>>
>> >
>> > 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> 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.
>> >>> 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...@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.

Reply via email to