multiformats / multicodec

Compact self-describing codecs. Save space by using predefined multicodec tables.
MIT License
340 stars 204 forks source link

Add JSON interoperability #273

Closed naure closed 2 years ago

naure commented 2 years ago

Add a note on JSON interoperability on the relevant codes that match the well-known UTF-8 characters {, [, and ".

This offers a clear upgrade path to multicodec for the uncountable applications already using JSON.

Unfortunately, two of the three codes are already assigned: { conflicts with the draft torrent-info codec. " conflicts with the permanent murmur3-x64-64 hash. [ is not assigned.

So we cannot make this perfectly self-describing and we must rely on context. Still, this is a perfectly sensible thing to write given the earlier and vastly wider adoption of JSON. In the specific contexts where the conflicting murmur3-x64-64 or torrent-info codecs are relevant, the codes maintain their meaning.

In the very common contexts where an application may be mixing existing JSON data with the multicodec system, the bytes 0x7b, 0x5b, or 0x22 should be interpreted as part of a JSON message: the code indicating object/array/string + the rest of the buffer as UTF-8.

This is what anyone would do in the situation anyway, so making it the documented approach to interoperability will facilitate the design or upgrade of many applications.