lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 27.09.2013 12:55, schrieb Enrique Garcia Cota:
> JSON expects strings in either UTF-8, UTF-16, UTF-32, in big endian or
> little-endian. Binary blobs outside that is considered invalid.

Am 01.10.2013 15:54, schrieb Enrique Garcia Cota:
> So far I've been able to validate utf-8 strings:
> 
> https://github.com/kikito/utf8_validator.lua
> 
> It parses all the bytes in the string and makes sure they all conform to
> UTF-8.
> 
> I'm now looking for ways to validate utf-16 & utf-32 (as well as their
> LE & BE versions). I have so far not found how to do that on the unicode
> standard.

Hello,

maybe there is some misunderstanding:  The entire JSON document has to
be either in UTF-8, UTF-16 or UTF-32.  All the strings in it have to use
the same encoding as the document.  Almost all JSON documents are
transmitted using UTF-8.  UTF-16 or UTF-32 are mostly used internally in
programming languages where UTF-16/32 is the default string representation.

If you actually had UTF-16/32 strings in Lua (which would be quite rare)
you would first have to convert them to UTF-8 in order to use one of the
existing JSON libraries.

So I would just check for UTF-8 and treat everything else as binary that
has to be encoded in Base64.

Best regards,

David Kolf