Skip to content

Deterministic JSON serialization and canonical equality — RFC 8785 JCS

License

Notifications You must be signed in to change notification settings

filip26/titanium-jcs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Titanium JCS

The JSON Canonicalization Scheme (JCS) defines a deterministic way to serialize JSON so that the same JSON data model always produces the same byte sequence.

This is critical for use cases such as digital signatures, hashing, and data integrity verification, where even small differences in whitespace, member ordering, or number formatting would otherwise break validation.

By normalizing JSON into a canonical form, JCS ensures interoperability across systems and guarantees stable, repeatable representations of data.

Titanium JCS is a Java implementation of the RFC 8785 JSON Canonicalization Scheme (JCS).

Java 8 CI Codacy Badge Codacy Badge javadoc Maven Central License

✨ Features

  • Canonical JSON Writer
    Deterministically serializes JSON values into a stable, repeatable form following RFC 8785.

  • Canonical JSON Equality Comparator
    Compares JSON values for equality under JCS rules, ensuring numbers, objects, and arrays are compared in their canonical form rather than raw text.

Example

// Canonicalize a JSON value and return the canonical string
var canonicalJson = Jcs.canonize(json);

// Canonicalize a JSON value and write canonical JSON to a writer
Jcs.canonize(json, writer);

// Compare two JSON values for canonical equality
if (Jcs.equals(json1, json2)) {
  // values are equal under RFC 8785 rules
}

Installation

Maven

<dependency>
    <groupId>com.apicatalog</groupId>
    <artifactId>titanium-jcs</artifactId>
    <version>1.1.1</version>
</dependency>

Ensure that the JSON-P provider is added to the classpath if it is not already present.

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>jakarta.json</artifactId>
    <version>2.0.1</version>
</dependency>

🛠️ LD-CLI

LD-CLI is a command-line utility for working with JSON, JSON-LD, CBOR-LD, multiformats, and related specifications.

It provides encoding, decoding, detection, analysis, and format conversion features, making it useful for inspecting identifiers, testing content addressing, and integrating multiformats into development workflows.

Example

Canonicalize JSON and write canonical JSON to stdout

cat test.json | ld-cli jcs

Contributing

All PR's welcome!

Building

Fork and clone the project repository.

> cd titanium-jcs
> mvn package

Resources

Commercial Support

Commercial support and consulting are available.
For inquiries, please contact: filip26@gmail.com