Skip to content

Latest commit

Β 

History

History
107 lines (72 loc) Β· 2.92 KB

index.md

File metadata and controls

107 lines (72 loc) Β· 2.92 KB

Canonicalize (AKA Normalize) πŸ“š

Canonicalization, which is also called normalization, transforms a resource into a "standard" representation.

This process is dependent on the type of the resource, but typically includes things such as:

  • Formatting based on a fixed standard
  • Sorting keys which do not (should not) change semantics
  • Rewriting literal values
  • Fixed Encoding

This is useful e.g. when testing, to compare output to a fixed expected outcome.

It also has an application in cryptography, where it's useful when "signing" things.

You can also use this as a "formatter".

RDF

enola canonicalize for RDF order statements by predicate IRI, for example:

$ ./enola canonicalize --load=test/picasso.ttl
...

Future versions may implement full RDF Dataset Canonicalization, see also this Working Group.

JSON

enola canonicalize for JSON transforms e.g. this canonicalize.json:

{% include "../../../test/canonicalize.json" %}

into this, using an RFC 8785 JSON Canonicalization Scheme (JCS) -inspired (but currently not fully compliant) algorithm:

$ ./enola canonicalize --load=test/canonicalize.json
...

or more nicely (--pretty) formatted:

$ ./enola canonicalize --pretty --load=test/canonicalize.json
...

Note how the order of the keys in the JSON changes, among other changes.

JSON-LD

enola canonicalize for JSON-LD transforms this canonicalize.jsonld:

{% include "../../../test/canonicalize.jsonld" %}
$ ./enola canonicalize --pretty --load=test/canonicalize.jsonld --output=test/canonicalize.jsonld.expected
...

into this - note how the 🎨 painters' order was swapped, because not just all map keys but the list itself was also ordered alphabetically by @id:

{% include "../../../test/canonicalize.jsonld.expected" %}

Markdown

Markdown canonicalization is also supported.

HTML

HTML canonicalization is also supported.

XML

XML canonicalization is also supported.