canonicalize
JSON canonicalize function
Last updated 2 days ago by samuelerdtman .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install canonicalize 
SYNC missed versions from official npm registry.

CI

canonicalize

JSON canonicalize function. Creates crypto safe predictable canonicalization of JSON as defined by RFC8785.

TypeScript type definitions are included.

Usage

Normal Example

import canonicalize from 'canonicalize';
const json = {
	"from_account": "543 232 625-3",
	"to_account": "321 567 636-4",
	"amount": 500,
	"currency": "USD"
}
console.log(canonicalize(json));
// output: {"amount":500,"currency":"USD","from_account":"543 232 625-3","to_account":"321 567 636-4"}

Crazy Example

import canonicalize from 'canonicalize';
const json = {
	"1": {"f": {"f":  "hi","F":  5} ,"\n":  56.0},
	"10": { },
	"":  "empty",
	"a": { },
	"111": [ {"e":  "yes","E":  "no" } ],
	"A": { }
}
console.log(canonicalize(json));
// output: {"":"empty","1":{"\n":56,"f":{"F":5,"f":"hi"}},"10":{},"111":[{"E":"no","e":"yes"}],"A":{},"a":{}}

Via CLI

The function can be executed directly using npx without explicit installation. This allows JSON files and arbitrary input to be canonicalized with standard input/output:

# Input from file
npx canonicalize < input.json > output.json

# Input from string
echo '{
	"from_account": "543 232 625-3",
	"to_account": "321 567 636-4",
	"amount": 500,
	"currency": "USD"
}' | npx canonicalize > simple-data.json

# Input from web API
curl --silent https://pokeapi.co/api/v2/pokemon/pikachu | npx canonicalize > pikachu.json

Install

As a library:

npm install canonicalize --save

As a CLI tool:

npm install -g canonicalize
canonicalize < input.json > output.json

Test

npm test

Current Tags

  • 3.0.0                                ...           latest (2 days ago)

12 Versions

  • 3.0.0                                ...           2 days ago
  • 2.1.0                                ...           a year ago
  • 2.0.0                                ...           3 years ago
  • 1.0.8                                ...           4 years ago
  • 1.0.7                                ...           4 years ago
  • 1.0.6                                ...           4 years ago
  • 1.0.5                                ...           5 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.3                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           7 years ago
  • 1.0.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 2
Last Month 2
Dependencies (0)
None
Dev Dependencies (4)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |