Skip to content

erdtman/java-json-canonicalization

Repository files navigation

Build Status Coverage Status Maven Central

java-json-canonicalization

Java JSON canonicalization JSON canonicalize implementation. Creates crypto safe predictable canocalization of JSON as defined by RFC8785

Usage

Example JSON

Normal

{
  "from_account": "543 232 625-3",
  "to_account": "321 567 636-4",
  "amount": 500,
  "currency": "USD"
}

Crazy

{
  "1": {"f": {"f":  "hi","F":  5} ,"\n":  56.0},
  "10": { },
  "":  "empty",
  "a": { },
  "111": [ {"e":  "yes","E":  "no" } ],
  "A": { }
}

Java

String json = new String(Files.readAllBytes(Paths.get("filename.json")));
JsonCanonicalizer jc = new JsonCanonicalizer(json);
System.out.println(jc.getEncodedString());

// output normal: {"amount":500,"currency":"USD","from_account":"543 232 625-3","to_account":"321 567 636-4"}
// output crazy: {"":"empty","1":{"\n":56,"f":{"F":5,"f":"hi"}},"10":{},"111":[{"E":"no","e":"yes"}],"A":{},"a":{}}

Install

Apache Maven

<dependency>
  <groupId>io.github.erdtman</groupId>
  <artifactId>java-json-canonicalization</artifactId>
  <version>1.1</version>
</dependency>

Gradle Groovy DSL

compile 'io.github.erdtman:java-json-canonicalization:1.1'

Gradle Kotlin DSL

compile(group = "io.github.erdtman", name = "java-json-canonicalization", version = "1.1")

Scala SBT

libraryDependencies += "io.github.erdtman" % "java-json-canonicalization" % "1.1"

Apache Ivy

<dependency org="io.github.erdtman" name="java-json-canonicalization" rev="1.1" />

Groovy Grape

@Grapes(
  @Grab(group='io.github.erdtman', module='java-json-canonicalization', version='1.1')
)

Leiningen

[io.github.erdtman/java-json-canonicalization "1.1"]

Apache Buildr

'io.github.erdtman:java-json-canonicalization:jar:1.1'

PURL

pkg:maven/io.github.erdtman/[email protected]