# json-canon

> Serialize JSON into a canonical format.

Latest version **1.0.1** (published 2023-05-12) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install json-canon
pnpm add json-canon
yarn add json-canon
bun add json-canon
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-05-12 |
| First published | 2023-05-10 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 28.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Michael Williams |
| Maintainers | ahdinosaur |
| Keywords | json, jcs, rfc8785, canon, canonical, canonicalize, crypto, hashable, hashing, signable, signing |

## Links

- npm: https://www.npmjs.com/package/json-canon
- Repository: https://github.com/ahdinosaur/json-canon
- Homepage: https://github.com/ahdinosaur/json-canon#readme
- Issues: https://github.com/ahdinosaur/json-canon/issues
- npm.io page: https://npm.io/package/json-canon

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.1 (latest) — 2023-05-12
- 1.0.0 — 2023-05-10

## README

# `json-canon`

## Install

```shell
npm install json-canon
```

## Example

```js
const serialize = require('json-canon')

const json = {
  from_account: "543 232 625-3",
  to_account: "321 567 636-4",
  amount: 500,
  currency: "USD"
}

console.log(serialize(json))
// {"amount":500,"currency":"USD","from_account":"543 232 625-3","to_account":"321 567 636-4"}
```

See [`./examples/basic.js`](./examples/basic.js)

## Usage

### `serialize = require('json-canon')`

```ts
function serialize(input: unknown): string;
```

## Bench

```txt
json-canon x 44,441 ops/sec ±0.42% (91 runs sampled)
JSON.stringify x 101,970 ops/sec ±0.37% (90 runs sampled)
fast-json-stable-stringify x 30,066 ops/sec ±0.35% (95 runs sampled)
json-stable-stringify x 23,099 ops/sec ±0.50% (93 runs sampled)
fast-stable-stringify x 35,560 ops/sec ±0.23% (91 runs sampled)
json-stringify-deterministic x 18,521 ops/sec ±0.37% (95 runs sampled)
faster-stable-stringify x 28,588 ops/sec ±0.20% (96 runs sampled)
fast-safe-stringify x 83,523 ops/sec ±0.23% (98 runs sampled)
safe-stable-stringify x 50,807 ops/sec ±0.26% (94 runs sampled)
canonicalize x 28,365 ops/sec ±0.79% (93 runs sampled)
json-canonicalize x 30,372 ops/sec ±0.56% (89 runs sampled)
The fastest is JSON.stringify
```

## License

```txt
Copyright 2023 Michael Williams

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```

## Related

- [`canonicalize`](https://github.com/erdtman/canonicalize)
- [`json-canonicalize`](https://github.com/snowyu/json-canonicalize.ts)

---
_Source: https://npm.io/package/json-canon · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
