4 ms·
Is JSON guaranteed to be ASCII? To clarify: Any "lookup table" that maps hex values to assumed character values is a portability red flag. When using them, it
by feralchimp 15y ago
Is JSON guaranteed to be ASCII?
To clarify: Any "lookup table" that maps hex values to assumed character values is a portability red flag. When using them, it's polite to add comments to explicitly call out the code page dependency and argue (from a spec or RFC, say) why that assumption is okay.
- michael_miller 15y agohttp://www.ietf.org/rfc/rfc4627 http://www.ietf.org/rfc/rfc4627 specifies that the encoding must be Unicode: "JSON text SHALL be encoded in Unicode. The default encoding is UTF-8."
- udp 15y agoI'm assuming UTF-8, so the characters I'm looking for should match up fine (\u escape sequences are also converted to UTF-8 for output).
- justincormack 15y ago\u is utf16 so you should be able to append two characters to get something in the extended unicode set outside ucs16. You dont seem to handle this; not sure how many parsers do. Also not sure you handle the case where the json invalidly terminates in the middle of a \u sequence. Just from a quick glance though, may be wrong.
- pantaloons 15y agoNeither the execution nor source character set (of C) is guaranteed to be ASCII though. This makes the general parsing as well as lines like "if (c >= 'A' && c <= 'F')" non-portable.
- udp 15y agoNon-portable to different character sets, not platforms. One could argue that the argument to json_parse is a UTF-8 string.