-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ser: some way to opt-in canonical JSON output #309
Comments
https://github.com/vtduncan/canonical_json may implement this already. If it can be as simple as swapping in Formatter, I would be open to providing it in serde_json. |
Ah, it looks like I didn't do enough due diligence investigation before filing this, as I missed the above crate. Also, it looks like it needs update to 1.0 and I hit this at the right time, as you reported it yesterday 😄 But yes, I would love to see it integrated here. |
@lucab If you haven't already implemented a JSON canonicalizer you may take a peek at: https://github.com/cyberphone/json-canonicalization |
I'm happy to focus on conventional JSON here and leave Canonical JSON to a different library. Thanks! |
@dtolnay ack, thanks. While at it, it looks the repo you originally linked disappeared in the meanwhile (and it was quite obsolete even before). Do you know about any up-to-date efforts on this? |
Standard-in-progress needing the same basic features: |
I think it moved to https://github.com/zmanian/canonical_json. But that library is a full fork of serde_json. The way I would recommend exposing this in a library instead is as a let mut ser = serde_json::Serializer::with_formatter(&mut out, canonical_json::Formatter);
t.serialize(&mut ser)?;
// equivalent for convenience
let cj = canonical_json::to_string(&t)?; |
The hard part is the formatting of numbers. I just ported 2000 lines of java code to .NET to achieve compatibility wit the Internet-Draft: |
Hey, @dtolnay! Thanks, and thanks for all the work on a really nice library and API! |
Yes @radu-matei, the formatter will need to sort the entries -- probably in Formatter::end_object since by then all the entries have been seen. |
When relying on digests of JSON data, it is often required that the content should be in some canonical form so that different serializer can deterministically reproduce the same data bit-by-bit.
The topic is a bit tricky as there is not a single JSON canonical format, but several similar efforts:
(I'd personally be interested in one of the latter twos)
I'm not sure whether a
CanonicalFormatter
would be enough for this or if it requires something more invasive?The text was updated successfully, but these errors were encountered: