Open sea-snake opened 1 year ago
Some topics of discussion:
blob
is hex string, should we use hex (simplicity) or base64 (compact)?opt
differs based on where it's used, makes it more straightforward for consuming services but less consistent for edge cases like opt opt null
.Example JS implementation compatible with autogenerated interfaceFactory
that's used in @dfinity/candid
: https://github.com/slide-computer/candid-json
Thanks a lot for the contribution, @sea-snake! I would make it clear that it is a one-way transformation, as it is a lossy, if no candid types are given.
However, with the typings, one should be able to go back and forth, right? Would it make sense to write down the transformation algorithm?
@benjizhai: Is this the right repository to create a PR in? This standard is about general data transformation and does not fit nicely in one of the existing categories (I think). Maybe SDK/dev-tooling related?
@frederikrothenberger It's indeed one way but it retains all the structure information needed to go both ways when you have the Candid IDL, as seen in the JS implementation above.
When communicating Candid data with JSON between web services, there are two options:
The latter is more accessible to services and dapps outside the IC ecosystem, they don't need to understand and decode CBOR to process incoming data.
A few examples:
This standard standardizes the JSON syntax of Candid type values for above use cases with a strong emphasis on making the data accessible for dapps outside the IC ecosystem without Candid knowledge.
The following technical details differ from other encoding formats of Candid types like CBOR:
opt
type differ depending on where its used, if possible without losing structural information,null
values are left out of the JSON string.The spec can be found at the following gist (until I've found a better place for it): https://gist.github.com/sea-snake/3043a9b83348111326a7699efb97e281