{"id":28390909,"url":"https://github.com/httpie/crosshash","last_synced_at":"2025-07-19T03:06:41.712Z","repository":{"id":190899316,"uuid":"680241484","full_name":"httpie/crosshash","owner":"httpie","description":"Stable, cross-platform JSON serialization and hashing for Python and JavaScript.","archived":false,"fork":false,"pushed_at":"2024-11-01T09:38:42.000Z","size":42,"stargazers_count":29,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-18T00:39:29.948Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","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/httpie.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-18T17:34:28.000Z","updated_at":"2025-04-24T16:02:28.000Z","dependencies_parsed_at":"2024-11-01T10:34:20.000Z","dependency_job_id":null,"html_url":"https://github.com/httpie/crosshash","commit_stats":null,"previous_names":["httpie/crosshash"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/httpie/crosshash","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httpie%2Fcrosshash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httpie%2Fcrosshash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httpie%2Fcrosshash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httpie%2Fcrosshash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/httpie","download_url":"https://codeload.github.com/httpie/crosshash/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httpie%2Fcrosshash/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265879487,"owners_count":23843125,"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-05-31T07:09:19.778Z","updated_at":"2025-07-19T03:06:41.701Z","avatar_url":"https://github.com/httpie.png","language":"Python","readme":"# `crosshash`\n\n[![Build status](https://github.com/httpie/crosshash/workflows/test/badge.svg)](https://github.com/httpie/crosshash/actions)\n\nStable, cross-platform JSON serialization and hashing for Python and JavaScript.\n\n## Motivation\n\nTo make it possible to compare and hash JSON objects in a stable way across platforms.\n\n## Installation\n\n### Python\n\n[![PyPi](https://badge.fury.io/py/crosshash.svg)](https://pypi.python.org/pypi/crosshash)\n\n```bash\npip install crosshash\n```\n\n### JavaScript\n\n[![NPM](https://badge.fury.io/js/crosshash.svg)](https://www.npmjs.com/package/crosshash)\n\n```bash\nnpm install crosshash\n```\n\n## Features\n\n\n### API\nThe following functions are implemented in both Python and JavaScript and the output is guaranteed to be the same:\n\n#### `crossjson(obj) → str`\n\n- Sort keys alphabetically\n- Ensure no unsafe numbers are present \n- Serialize using the same format as `JSON.stringify()` (lowest common denominator)\n\n#### `crosshash(obj) → str`\n\n- Serialize the object with `crossjson()`\n- Hash the resulting string with MD5\n\n\n### CLI\n\nBoth Python and JavaScript implementations come with a CLI that can be used to generate stable JSON and hashes.\n\n```bash\nJSON='{\"B\":2,\"C\":[1,2,3],\"A\":1}'\n[ $(crosshash-js --hash \"$JSON\") == $(crosshash-py --hash \"$JSON\") ] \u0026\u0026 echo 'It’s a match!'\n[ $(crosshash-js --json \"$JSON\") == $(crosshash-py --json \"$JSON\") ] \u0026\u0026 echo 'It’s a match!'\n```\n\n\n## Usage\n\n### Python\n\n#### API\n\n```python\nfrom crosshash import crossjson, crosshash, CrossHashError, MAX_SAFE_INTEGER\n\nobj = {'B': 2, 'C': [1, 2, 3], 'A': 1}\n\n# Generate stable JSON:\nassert crossjson(obj) == '{\"A\":1,\"B\":2,\"C\":[1,2,3]}'  \n\n# Generate stable hash:\nassert crosshash(obj) == '12982c60a9a8829ea4eeb2e1e7e1e04e'\n\n# Throws `CrossHashError`:\ncrosshash({'A': MAX_SAFE_INTEGER + 1})  \n```\n\n#### CLI\n\nYou can invoke `crosshash.py` directly or use `python -m crosshash`. The package also installs an executable called `crosshash-py`.\n\n```bash\n$ crosshash-py --json '{\"B\": 2, \"C\": [1, 2, 3], \"A\": 1}'\n{\"A\":1,\"B\":2,\"C\":[1,2,3]}\n```\n\n```bash\n$ crosshash-py --hash '{\"B\": 2, \"C\": [1, 2, 3], \"A\": 1}'\n12982c60a9a8829ea4eeb2e1e7e1e04e\n```\n\n\n### JavaScript\n\n#### API\n\nThe library runs in the browser and Node.js and comes with [TypeScript definitions](./crosshash.d.ts).\n\n```javascript\nconst {crossjson, crosshash, CrossHashError} = require('crosshash')\n\nconst obj = {B: 2, C: [1, 2, 3], A: 1}\n\n// Generate stable JSON:\nassert(crossjson(obj) === '{\"A\":1,\"B\":2,\"C\":[1,2,3]}')\n\n// Generate stable hash:\nassert(crosshash(obj) === '12982c60a9a8829ea4eeb2e1e7e1e04e')\n\n// Throws `CrossHashError`:\ncrosshash({A: Number.MAX_SAFE_INTEGER + 1}) \n```\n\n#### CLI\n\nYou can invoke `crosshash.js` directly or using `npx`. The package also installs an executable called `crosshash-js`.\n\n```bash\n$ crosshash-js --json '{\"B\": 2, \"C\": [1, 2, 3], \"A\": 1}'\n{\"A\":1,\"B\":2,\"C\":[1,2,3]}\n```\n\n```bash\n$ crosshash-js --hash '{\"B\": 2, \"C\": [1, 2, 3], \"A\": 1}'\n12982c60a9a8829ea4eeb2e1e7e1e04e\n```\n\n## Stability\n\nThe Python/JavaScript libraries with matching versions are guaranteed to produce the same output. The format is unlikely to change but it’s not guaranteed to be stable across different versions. Therefore, it’s not recommended to cache the output. This may change as the library matures to v1.0.\n\n\n\n## Test suite\n\nTo ensure consistency, the [test suite](./tests) invokes the Python and JavaScript implementations of `crossjson()` and `crosshash()` on the [same data](./tests/cases.py) and compares the results.\n\n\n## Development\n\nIt should be fairly straightforward to add support for other languages.\n\n```bash\ngit clone git@github.com:httpie/crosshash.git\ncd ./crosshash\nmake install\nmake test\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttpie%2Fcrosshash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhttpie%2Fcrosshash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttpie%2Fcrosshash/lists"}