On Fri, Sep 27, 2013 at 12:47:30PM +0000, D. Matt Placek wrote:
> On Fri, Sep 27, 2013 at 10:55 AM, Enrique Garcia Cota <
kikito@gmail.com>wrote:
>
> > Hello there,
> >
> > In my current setup I'm treating some strings in Lua and then storing them
> > in JSON.
> >
> > JSON expects strings in either UTF-8, UTF-16, UTF-32, in big endian or
> > little-endian. Binary blobs outside that is considered invalid.
> >
> Unfortunately, some of the data I'm receiving can be binary. I need to
> > detect those cases and escape the binary data somehow (probably with Base64
> > encoding).
> >
>
> The JSON spec (RFC4627) says: "All Unicode characters may be placed within
> the quotation marks except for the characters that must be escaped: quotation
> mark, reverse solidus, and the control characters (U+0000 through U+001F)."
>
> I use a very simple JSON encoder that just scans the string character by
> character and substitutes the correct escape sequence whenever one of these
> characters is encountered. I don't think you need to resort to Base64 or
> other binary encodings unless you really want to.