{"id":28645696,"url":"https://github.com/engineerd/cjson","last_synced_at":"2025-06-13T01:40:28.080Z","repository":{"id":40464753,"uuid":"218893336","full_name":"engineerd/cjson","owner":"engineerd","description":"Canonical JSON for Rust, compatible with the canonical implementations from Docker and TUF","archived":false,"fork":false,"pushed_at":"2022-05-06T16:25:46.000Z","size":154,"stargazers_count":3,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-06T01:05:08.183Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/engineerd.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-01T01:52:18.000Z","updated_at":"2021-10-27T18:14:30.000Z","dependencies_parsed_at":"2022-08-09T21:12:46.949Z","dependency_job_id":null,"html_url":"https://github.com/engineerd/cjson","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/engineerd/cjson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engineerd%2Fcjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engineerd%2Fcjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engineerd%2Fcjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engineerd%2Fcjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/engineerd","download_url":"https://codeload.github.com/engineerd/cjson/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engineerd%2Fcjson/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259563624,"owners_count":22877131,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-13T01:40:00.565Z","updated_at":"2025-06-13T01:40:28.064Z","avatar_url":"https://github.com/engineerd.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Canonical JSON serialization for Rust\n\n![Build and Test](https://github.com/engineerd/cjson/workflows/Build%20and%20Test/badge.svg)\n[![docs.rs](https://docs.rs/cjson/badge.svg?version=0.1.1)](https://docs.rs/cjson/0.1.1/cjson/)\n[![Crates.io](https://img.shields.io/crates/v/cjson.svg)](https://crates.io/crates/cjson)\n\nThis is an implementation for a canonical JSON serializer that tries to be\ncompliant with [the OLPC minimal specification for canonical JSON][olpc].\nAdditionally, the implementation also tries to be fully compatible with the [Go\ncanonical JSON implementation][docker/go/canonical] used across the Docker and\nNotary ecosystem. If you find any inconsistencies with the result of the\nserialization, please open an issue.\n\nExample - reading a JSON file and printing its canonical representation:\n\n```rust\nlet res: serde_json::Value =\n    serde_json::from_reader(input).expect(\"cannot deserialize input file\");\n\nprintln!(\n    \"{}\",\n    cjson::to_string(\u0026res).expect(\"cannot write canonical JSON\")\n);\n```\n\n\u003e Note: this crate aims to always be compilable to the `wasm32-unknown-unknown`\n\u003e and `wasm32-wasi` targets.\n\n### Building and contributing\n\nThis project welcomes contributions of any kind, particularly additional test\ncases.\n\nTo build:\n\n```\n$ cargo build\n$ cargo test\n```\n\nThe `testdata` directory is structured in the following way:\n\n- in the root of the directory are JSON files whose name is represented by the\n  SHA256 digest of their canonical JSON representation, as calculated using the\n  [`github.com/docker/go/canonical`][docker/go/canonical] package. The test case\n  will use compare the SHA256 digest obtained after serializing using this\n  implementation, to the file name, and they are expected to be equal.\n\nTo add a new test case, you can use the [`canonjson`][canonjson] binary, which\nis a CLI wrapper over the Go canonical JSON implementation:\n\n```\n$ go get github.com/technosophos/canonjson\n$ canonjson target-file.json | sha256sum\n```\n\nAt this point, rename `target-file.json` to the `\u003ccomputed-SHA256\u003e.json`, the\nmove it in the root of the `testdata` directory.\n\n- the `errors` sub-directory contains valid JSON files (if the files are not\n  valid JSON files, the tests will fail), but which contain characters that are\n  not permitted in canonical JSON - so trying to represent them in canonical\n  JSON should produce an error.\n\nFinally, the `scripts/integration.sh` script contains a very rudimentary test of\nthe CLI from `main.rs` - and compares the digest of obtained there with the\ndigest obtained from serializing with the Go implementation. Ideally, we would\nadd more implementations of canonical JSON to test against. Note that you also\nneed the `canonjson` binary used earlier to execute this script.\n\n### Notes and acknowledgement\n\n- this implementation was initially based on the canonical JSON serialization\n  used in the [Rust TUF crate][rust-tuf].\n\n[olpc]: http://wiki.laptop.org/go/Canonical_JSON\n[docker/go/canonical]: https://github.com/docker/go/tree/master/canonical/json\n[canonjson]: https://github.com/technosophos/canonjson\n[rust-tuf]: https://github.com/heartsucker/rust-tuf/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fengineerd%2Fcjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fengineerd%2Fcjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fengineerd%2Fcjson/lists"}