{"id":22202254,"url":"https://github.com/rumkin/normjson","last_synced_at":"2025-09-02T12:34:23.841Z","repository":{"id":13590235,"uuid":"74821928","full_name":"rumkin/normjson","owner":"rumkin","description":"Convert object into JSON string according to schema","archived":false,"fork":false,"pushed_at":"2022-12-30T19:34:48.000Z","size":739,"stargazers_count":0,"open_issues_count":12,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-04T02:51:21.938Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rumkin.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","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":"2016-11-26T11:32:53.000Z","updated_at":"2020-02-09T13:12:37.000Z","dependencies_parsed_at":"2023-01-11T20:21:03.034Z","dependency_job_id":null,"html_url":"https://github.com/rumkin/normjson","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fnormjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fnormjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fnormjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fnormjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rumkin","download_url":"https://codeload.github.com/rumkin/normjson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245383118,"owners_count":20606265,"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":"2024-12-02T16:13:08.145Z","updated_at":"2025-03-25T01:42:29.810Z","avatar_url":"https://github.com/rumkin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NormJSON\n\n![Travis CI](https://img.shields.io/travis/rumkin/normjson.png)\n\nConvert JS values into deterministic JSON. It can sort keys in ascending\norder or according to scheme. Normjson is useful for hash algorithms to generate the same hashsum in different js environments.\n\n## Installation\n\nInstall via npm\n```bash\nnpm i normjson\n```\n\nRequire from unpkg.com:\n\n```html\n\u003cscript src=\"https://unpkg.com/normjson@1.3.0/dist/normjson.js\"\n    integrity=\"St/z56cj/u6TzqsuQ/H0/ve0ZreNswh5UbYrgSCQyN58F/0s0FN6E+Ak3a8ZAy5q\"\n\u003e\u003c/script\u003e\n\u003cscript src=\"https://unpkg.com/normjson@1.3.0/dist/normjson.min.js\"\n    integrity=\"qPKIijQ3VZP98fNmZUtRxsDHGdqBNkAJLyg5jWwvQAhr16EBJqkkqFfpTkNmPM6h\"\n\u003e\u003c/script\u003e\n```\n\n## Example\n\nNormjson will create the same JSON string from objects with different props order and `JSON.stringify` does not:\n\n```javascript\nconst object1 = {a: 1, b: 2};\nconst object2 = {b: 2, a: 1};\n\nJSON.stringify(object1) === JSON.stringify(object2); // =\u003e false\nnormjson(object1) === normjson(object2); // =\u003e true\n```\n\n## Scheme types\n\n### No scheme\n\nIf no scheme specified then properties sorting by name in ascending order:\n\n```javascript\nnormjson({c: 3, a:1, b:2});\n```\n\nCoverts to:\n\n```json\n{\"a\":1,\"b\":2,\"c\":3}\n```\n\nScheme could be presented in several ways.\n\n### Array scheme\n\nArray scheme contains list of properties which should be converted in specified\norder.\n\n```javascript\nnormjson({a:1, b:2, c: 3}, ['b', 'a']);\n```\n\nConvets to:\n```json\n{\"b\":2,\"a\":1}\n```\n\nIt allow to specify *rest of props* with true and sorts them by key names:\n```javascript\nnormjson({b: 3, c: 2, a: 1}, ['c', true]);\n```\n\nCoverts to:\n\n```json\n{\"c\":3,\"a\":1,\"b\":2}\n```\n\nRest of props could be set as the first, the last or in the middle.\n\n\n### Object scheme\n\nObject scheme allow nesting.\n\n```javascript\nnormjson({a:{b: 1, c:2}}, {a:{c: true}});\n```\n\nCoverts to:\n\n```json\n{\"a\":{\"c\":2}}\n```\n\n### Function scheme\n\nFunction as a scheme should return other type of scheme (array, object, no).\nThe first argument is a document.\n\n## License\n\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frumkin%2Fnormjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frumkin%2Fnormjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frumkin%2Fnormjson/lists"}