Documentation
¶
Overview ¶
Package jcs implements RFC 8785 JSON Canonicalization Scheme serialization.
Given a parsed Value tree (from jcstoken), this package produces the exact canonical byte sequence specified by RFC 8785. It depends on jcsfloat for ECMA-262-compliant number serialization and uses UTF-16 code-unit ordering for object property name sorting as required by RFC 8785 §3.2.3.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Canonicalize ¶ added in v0.3.0
Canonicalize parses JSON input and produces the RFC 8785 JCS canonical byte sequence. It is equivalent to calling jcstoken.Parse followed by Serialize.
API-CANON-001: Output is identical to Parse followed by Serialize.
Example ¶
package main
import (
"fmt"
"log"
"github.com/lattice-substrate/json-canon/jcs"
)
func main() {
input := []byte(`{ "b" : 2, "a" : 1 }`)
canonical, err := jcs.Canonicalize(input)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(canonical))
}
Output: {"a":1,"b":2}
func CanonicalizeWithOptions ¶ added in v0.3.0
CanonicalizeWithOptions is like Canonicalize but accepts parser options.
API-CANON-002: Options are passed through to ParseWithOptions.
func Serialize ¶
Serialize produces the RFC 8785 JCS canonical byte sequence for a parsed JSON value.
CANON-ENC-001: Output is UTF-8. CANON-WS-001: No insignificant whitespace.
Example ¶
package main
import (
"fmt"
"log"
"github.com/lattice-substrate/json-canon/jcs"
"github.com/lattice-substrate/json-canon/jcstoken"
)
func main() {
input := []byte(`{ "z" : true, "a" : [3, 1] }`)
v, err := jcstoken.Parse(input)
if err != nil {
log.Fatal(err)
}
canonical, err := jcs.Serialize(v)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(canonical))
}
Output: {"a":[3,1],"z":true}
Types ¶
This section is empty.