1.0.0 • Published 4 years ago

redistojson v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

For those seeking a means to convert redis "string" data to JSON object for easy parsing.

Special Thanks to my friend, Augustine Best and also Jerry for their amazing contributions.

How to use

step 1: Install reformat-date

npm install redistojson --save

step 2: Require the package in your project

const redistojson = require('redistojson');

step 3: Pass in the redis data you wish to convert as an argument -for example case 1: having a list of persons data

const redisData = "Persons,[name,adegoke,address,gentlemen in ikorodu,age,90,sex,masculine,pet,Bethy,wife,Mai,school,],[name,Augustine Best,address,Enugu,age,32,sex,male,pet,Cowboy,wife,Juin,school,FUTO],[name,Femi,address,Surulere,age,45,sex,male,pet,Cat,wife,Queen,school,UNILAG],[name,Peter,address,Ikeja,age,23,sex,male,pet,Dog,wife,Angela,school,OAU],[name,Betty,address,Porharcourt,age,21,sex,female,pet,Elephant,wife,princess,school,UNIBEN],[name,Jessie,address,Toronto,age,49,sex,male,pet,Goat,wife,Stephanie,school,Harvard]";

console.log(redistojson(redisData));

// result 
{
  Persons: [
    {
      name: 'adegoke',
      address: 'gentlemen in ikorodu',
      age: '90',
      sex: 'masculine',
      pet: 'Bethy',
      wife: 'Mai',
      school: ''
    },
    {
      name: 'Augustine Best',
      address: 'Enugu',
      age: '32',
      sex: 'male',
      pet: 'Cowboy',
      wife: 'Juin',
      school: 'FUTO'
    },
    {
      name: 'Femi',
      address: 'Surulere',
      age: '45',
      sex: 'male',
      pet: 'Cat',
      wife: 'Queen',
      school: 'UNILAG'
    },
    {
      name: 'Peter',
      address: 'Ikeja',
      age: '23',
      sex: 'male',
      pet: 'Dog',
      wife: 'Angela',
      school: 'OAU'
    },
    {
      name: 'Betty',
      address: 'Porharcourt',
      age: '21',
      sex: 'female',
      pet: 'Elephant',
      wife: 'princess',
      school: 'UNIBEN'
    },
    {
      name: 'Jessie',
      address: 'Toronto',
      age: '49',
      sex: 'male',
      pet: 'Goat',
      wife: 'Stephanie',
      school: 'Harvard'
    }
  ]
}

case 2: having an object of a data

const redisData = "Person,name,adegoke,address,gentlemen in ikorodu,age,90,sex,mascufeline,pet,Bethy,wife,Mai,school,";

console.log(redistojson(redisData)); 

// result
{
  Person: {
    name: 'adegoke',
    address: 'gentlemen in ikorodu',
    age: '90',
    sex: 'mascufeline',
    pet: 'Bethy',
    wife: 'Mai',
    school: ''
  }
}

All the best