5 ms·
How different is CBOR compared to BSON? Both seem to be binary json-like representations. Edit: BSON seems to contain more data types than JSON, and as such it
by zbendefy 1y ago
How different is CBOR compared to BSON? Both seem to be binary json-like representations.
Edit:
BSON seems to contain more data types than JSON, and as such it is more complex, whereas CBOR doesn't add to JSON's existing structure.
- EdSchouten 1y agoThat's not entirely true: with CBOR you can add custom data types through custom tags. A central registry of them is here: https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml This is, for example, used by IPLD (https://ipld.io https://ipld.io) to express references between objects through native types (https://github.com/ipld/cid-cbor/ https://github.com/ipld/cid-cbor/).
- maxbond 1y agoI think parsing BSON is simpler than parsing JSON, BSON has additional types but the top level is always a document. Whereas the following are all valid JSON: - `null` - `"hello"` - `[1,2,NaN]` Additionally, BSON will just tell you what the type of a field is. JSON requires inferring it.
- zokier 1y agoNaN is not part of JSON by any spec. Top level scalar values were disallowed by RFC 4627.
- maxbond 1y agoFair enough. I'm not sure how much JSON parsers in the wild care about that spec. I just tried with Python and it was happy to accept scalars and NaN. JavaScript rejected NaN but was happy to accept a scalar. But sure, compliant parsers can disregard those cases.