json-slim

0.2.1 • Public • Published

JSON-Slim

Build Status Dependencies

Minify JSON better than JSON.stringify().

It achieves this by converting Numbers, number Strings and Booleans to a shorter form. You should be aware of this in your application, type checks might fail.

Installation

npm i json-slim

Example

var slim = require('json-slim');
 
var json = slim({
    true:                  true,
    false:                 false,
    number:                123000,
    numberString:          '123000',
    decimalFraction:       0.00123,
    decimalFractionString: '0.00123',
    exponent:              1.23E+5,
    exponentString:        '1.23e+5',
    customField:           'Tom Marvolo Riddle'
}, {
    // JSON-slim reports only to you
    report:    true,
    // You can add your own minifiers too
    minifiers: [
        {
            // RegExp Pattern
            pattern: '"Tom Marvolo Riddle"',
            replace: function(string) {
                return '"I am Lord Voldemort"';
            }
        }
    ]
});
 
console.log(json);

Output:

JSON-Slim: 90% of original.
{"true":1,"false":0,"number":123e3,"numberString":123e3,"decimalFraction":123e-5,"decimalFractionString":123e-5,"exponent":123e3,"exponentString":123e3,"customField":"I am Lord Voldemort"}

Even less?

Check out json-lean if your JSON requests have the same object structure.

Package Sidebar

Install

npm i json-slim

Weekly Downloads

1

Version

0.2.1

License

MIT

Last publish

Collaborators

  • armin.rosu