Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    sjsonpublic

    sjson NPM version Build Status Dependency Status License

    Squishable JSON strings. To assist with JSON compression by stripping variable name double quotes and yet the squished strings can still be parsed by javascript.

    Install 🔨

    npm install sjson
    

    Usage 🔧

    var SJSON = require('sjson');
     
    var data  = {first:"joe", last:"smith", age:27};
    var json  = JSON.stringify(data);
    var sjson = SJSON.squish(json);
    var json2 = SJSON.unsquish(sjson);
    var data2 = JSON.parse(json2);
     
    console.log(data);  // {"first": "joe", "last": "smith", "age": 27}
    console.log(json);  // {"first":"joe","last":"smith","age":27}
    console.log(sjson); // {first:"joe",last:"smith",age:27}
    console.log(json2); // {"first":"joe","last":"smith","age":27}
    console.log(data2); // {"first": "joe", "last": "smith", "age": 27}

    While it may not look like much, every byte helps when you scale :-) In this example we get at 15% headstart on any addition compression we may want to do.

    Directly operate with objects 🔧

    sjson = SJSON.squishify(data); // do both JSON.stringify and SJSON.squish
    data2 = SJSON.parse(sjson);    // do both SJSON.unsquish and JSON.parse
     
    console.log(data);  // {"first": "joe", "last": "smith", "age": 27}
    console.log(sjson); // {first:"joe",last:"smith",age:27}
    console.log(data2); // {"first": "joe", "last": "smith", "age": 27}

    Generate browser callbacks 🔧

    out = SJSON.callbackify(data, 'callme'); // function wrapped SJSON.squishify
    console.log(out);                        // callme({first:"joe",last:"smith",age:27});

    Credits 👥

    Derek and Bergi

    License: MIT 🔓

    Keywords

    none

    install

    npm i sjson

    Downloadsweekly downloads

    15

    version

    0.2.8

    license

    none

    repository

    githubgithub

    last publish

    collaborators

    • avatar