modules/json/canonicalization.zzm

json-canonicalization-0.0.1 documentation

Package

Name
json-canonicalization
Version
0.0.1
Uploaded
2026-06-09 22:34:02
Repository
https://github.com/tobyink/zuzu-json-canonicalization
Dependencies
Metadata
zuzu-distribution.json
Archive
Download .tar.gz

NAME

json/canonicalization - JSON Canonicalization Scheme (RFC 8785).

SYNOPSIS

  from json/canonicalization import jcs_canonicalize;

  say( jcs_canonicalize( { "b": 2, "a": 1 } ) );   // {"a":1,"b":2}
  say( jcs_canonicalize( [null, true, 1.5] ) );    // [null,true,1.5]

DESCRIPTION

Implements the JSON Canonicalization Scheme defined by RFC 8785.

The single exported function jcs_canonicalize accepts any JSON-compatible ZuzuScript value (null, Boolean, Number, String, Array, or Dict/PairList) and returns its canonical JSON string representation.

Key properties of the canonical form:

  • Object keys are sorted by UTF-16 code unit order.
  • No whitespace between tokens.
  • Numbers use IEEE 754 / ES2019 Number::toString() serialization.
  • Strings use \" \\ and shorthand \b \t \n \f \r escapes;

    remaining control characters (U+0000–U+001F) use lowercase \uXXXX.

EXPORTS

jcs_canonicalize(value) -> String

Returns the RFC 8785 canonical JSON serialization of value.

COPYRIGHT AND LICENCE

json/canonicalization is copyright Toby Inkster.

It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.