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

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

  • Non-recursive 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.

  • Uniform, JSON Library-Agnostic API
    Built on a uniform Tree I/O API for JSON data processing.
    Jackson and Jakarta are supported out of the box.

Example

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

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

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

📦 Installation

<dependency>
    <groupId>com.apicatalog</groupId>
    <artifactId>titanium-jcs</artifactId>
    <version>${titanium-jcs.version}</version>
</dependency>

<!-- Include at least one Tree I/O JSON adapter -->

<!-- Jackson 2 -->
<dependency>
    <groupId>com.apicatalog</groupId>
    <artifactId>tree-io-jackson2</artifactId>
    <version>${tree-io.version}</version>
</dependency>

<!-- Jakarta (JSONP) -->
<dependency>
    <groupId>com.apicatalog</groupId>
    <artifactId>tree-io-jakarta</artifactId>
    <version>${tree-io.version}</version>
</dependency>
<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

Contributions are welcome! Please submit a pull request.

Building

Fork and clone the repository, then build with Maven:

> cd titanium-jcs
> mvn package

Resources

💼 Commercial Support

Commercial support and consulting are available.
For inquiries, please contact: [email protected]

About

Deterministic JSON serialization and canonical equality. RFC 8785 JCS

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages