Code Monkey home page Code Monkey logo

canonify's Introduction

Canonical JSON

JSON.canonify(value) produces a canonical form of JavaScript Object Notation (JSON). The canonical form is very similar to the form defined by ECMAScript for JSON.stringify(value). The only difference is one additional constraint: key/value pairs of an object are sorted in lexical order of keys.

null, true, and false are already in canonical form.

The canonical form of a string is bracketted by " characters. It uses 7 of the 8 \x escapes: \" \\ \b \f \n \r \t. A reverse solidus is not escaped, ie \/ is not used in canonical form. The remaining 27 control characters from U+0000 to U+001F are escaped as \u00xx, using lowercase hex digits. No other characters are escaped.

Examples of numbers in canonical form are 64000, 23.7, 0.001, 6.22e+23, and -1.60217646e-19. No exponent is used for numbers โ‰ฅ 0.000001 and < 1,000,000,000,000,000,000,000 (1e21), which includes all 64-bit integers. Normalized scientific notation is used for positive numbers outside this range. The exponent is a lowercase e and always include a + or - sign. The canonical form of zero is 0. The canonical form of a negative number is - followed by the canonical form of its absolute value.

The canonical form of an array has no whitespace before or after the brackets or comma separators.

The canonical for of an object has keys in lexical order, based on the code points of the unescaped characters of the keys. There is no whitespace before or after the braces, colon separators, or comma separators. Keys are in double quotes as they are strings in canonical form.

Code status

Build Status

canonify's People

Contributors

manger avatar

Stargazers

doc-hex avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.