npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-serializer-lib

v1.0.1

Published

A library to decrease the size of the JSON before sending it over the network and restoring it when it is received.

Downloads

2

Readme

Instalation

npm i json-serializer-lib

Basic use

var jsonSerializer = require('json-serializer-lib');



const OBJECT_TO_SERIALIZE =  {
  ///////////////////////////////////////////////////////
  // Predefined default values
  property_predef_val_01: 0,           // Zero.
  property_predef_val_02: '',          // Empty string.
  property_predef_val_03: false,       // False.
  property_predef_val_04: [],          // Empty array.
  property_predef_val_05: {},          // Empty object.
  property_predef_val_06: undefined,   // UNDEFINED.
  property_predef_val_07: null,        // NULL.
  property_predef_val_08: {
    subProperty01: 0                    // Nested Zero.
  },
  property_predef_val_09: {
    subProperty01: ''                   // Nested empty string.
  },
  property_predef_val_10: {
    subProperty01: false                // Nested false.
  },
  property_predef_val_11: {
    subProperty01: []                   // Nested empty array.
  },
  property_predef_val_12: {
    subProperty01: {}                   // Nested empty object.
  },
  property_predef_val_13: {
    subProperty01: undefined            // Nested UNDEFINED.
  },
  property_predef_val_14: {
    subProperty01: null                 // Nested NULL.
  },
  ///////////////////////////////////////////////////////
  // User defined default values
  property_user_def_val_01: -1,        // A number different from 0.
  property_user_def_val_02: '<NONE>',  // A not empty string.
  property_user_def_val_03: true,      // A not false value.
  property_user_def_val_04: [ -100 ],  // A not empty array as default value.
  property_user_def_val_05: {          // A not empty object as default value.
    this_prop_dont_need_to_be_mapped: '<N/A>'
  },
  ///////////////////////////////////////////////////////
  // Values
  property01: Math.PI,
  property02: 'Hello WORLD!!!',
  property03: true,
  property04: [ 1, 2, 3 ],
  property05: {
    subProperty01: 'Happy coding',
    subProperty02: new Date()
  }
};


const SCHEMA = {
  ///////////////////////////////////////////////////////
  // Predefined default values
  't@n_property_predef_val_01': 'ppv01',
  't@s_property_predef_val_02': 'ppv02',
  't@b_property_predef_val_03': 'ppv03',
  't@a_property_predef_val_04': 'ppv04',
  't@o_property_predef_val_05': 'ppv05',
  't@n_property_predef_val_06': 'ppv06',
  't@o_property_predef_val_07': 'ppv07',
  't@o_property_predef_val_08': {
    _propName: 'ppv08',
    _sch: {
      't@n_subProperty01': 'sp01'
    }
  },
  't@o_property_predef_val_09': {
    _propName: 'ppv09',
    _sch: {
      't@s_subProperty01': 'sp01'
    }
  },
  't@o_property_predef_val_10': {
    _propName: 'ppv10',
    _sch: {
      't@b_subProperty01': 'sp01'
    }
  },
  't@o_property_predef_val_11': {
    _propName: 'ppv11',
    _sch: {
      't@a_subProperty01': 'sp01'
    }
  },
  't@o_property_predef_val_12': {
    _propName: 'ppv12',
    _sch: {
      't@o_subProperty01': 'sp01'
    }
  },
  't@o_property_predef_val_13': {
    _propName: 'ppv13',
    _sch: {
      't@n_subProperty01': 'sp01'
    }
  },
  't@o_property_predef_val_14': {
    _propName: 'ppv14',
    _sch: {
      't@o_subProperty01': 'sp01'
    }
  },
  ///////////////////////////////////////////////////////
  // User defined default values
  't@n_property_user_def_val_01':{
    _propName: 'puv01',
    _defVal: -1
  },
  't@s_property_user_def_val_02':{
    _propName: 'puv02',
    _defVal: '<NONE>'
  },
  't@b_property_user_def_val_03':{
    _propName: 'puv03',
    _defVal: true
  },
  't@a_property_user_def_val_04':{
    _propName: 'puv04',
    _defVal: [ -100  ]
  },
  't@o_property_user_def_val_05':{
    _propName: 'puv05',
    _defVal: { // The default value is an entire object.
      this_prop_dont_need_to_be_mapped: '<N/A>'
    }
  },
  ///////////////////////////////////////////////////////
  // Values
  't@n_property01': 'p01',
  't@s_property02': 'p02',
  't@b_property03': 'p03',
  't@a_property04': 'p04',
  't@o_property05': {
    _propName: 'p05',
    _sch: {
      't@s_subProperty01': 'sp01',
      't@d_subProperty02': 'sp02'
    }
  }
};


const serializedJSON = jsonSerializer.Model.serialize(OBJECT_TO_SERIALIZE, SCHEMA).serializedJSON;
const deserializedJSON = jsonSerializer.Model.deserialize(serializedJSON, SCHEMA).deserializedJSON;


console.log("Serialized:\n", serializedJSON);
console.log("Deserialized:\n", deserializedJSON);

Please visit the Project's Wiki, for more details in how to define the schema and how to configure to your needs.