function · Browser and Node

# canonicalJson

JSON Canonicalization Scheme (RFC 8785) — the byte form eddsa-jcs-2022 and ecdsa-jcs-2019 hash.

Object keys are sorted by UTF-16 code unit (what `Array.prototype.sort` does on strings, which is what RFC 8785 §3.2.3 specifies), strings are serialised with JSON's own escaping, and numbers use the shortest round-tripping form — which for the integers and JSON doubles a Trust Task document carries is exactly `JSON.stringify(n)`. Trust Task documents carry no number outside the safe-integer / plain-double range, so no bespoke number formatter is needed.

`@toip-tools/trust-core` · [View source](https://github.com/yourbuddyconner/toip-tools/blob/main/node_modules/@openvtc/trust-tasks-proof/dist/jcs.d.ts#L12)

Import:

```ts
import { canonicalJson } from "@toip-tools/trust-core";
```

## Declaration

Signature:

```ts
canonicalJson(value: unknown): string;
```

### Parameters

- **`value` (required)**: `unknown`

### Returns

`string`

[Usage guide](https://toip.tools/toolkit/trust-core/#usage) · [Error handling](https://toip.tools/toolkit/trust-core/#errors) · [All exports](https://toip.tools/toolkit/trust-core/api/)

---

This is the Markdown version of https://toip.tools/toolkit/trust-core/api/canonicalJson/. An index of the documentation for AI assistants is at https://toip.tools/llms.txt.
