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-light

v1.0.8

Published

Allow to extend yaml or json files configuration

Downloads

360

Readme

Json Light

Json Light is a json compressor, generating a new simplified json file from a type definition.

The type can be written by us or generated by the library itself.

Json Light extracts the property tags from a json object and stores the values in an array.

Features

  • Compress json generating a new valid json
  • Allows to get type from json data
  • In the event that you do not want to pass the type to the compress function, it will be generated from the data and stored within the resulting json, allowing it to be later decompressed without the need to pass the type
  • CLI

Methods

.type(data:any)

get type from json data

  • Params:
    • data : json data

.compress(data:any, type?:string)

get a compressed json

  • Params:
    • data : json data
    • type : type (optional)
    • mapping : replace names of properties for key and save mapping (optional)

.decompress(data:any, type?:string)

decompress a previously compressed json getting the original json

  • Params:
    • data : json data
    • type : type (optional)

Quick start

import { JsonLight } from 'json-light'

const data = {
 name: 'Spain',
 region: 'Europe',
 phoneCode: '34',
 timezones: [
  { name: 'Madrid', offset: 1, pos: { lat: 40.4165, log: -3.70256 } },
  { name: 'Ceuta', offset: 1, pos: { lat: 35.8883, log: -5.3162 } },
  { name: 'Canary', offset: 0, pos: { lat: 28.1248, log: -15.43 } }
 ]
}

Get Type:

const type = JsonLight.type(data)
console.log(type)

Output:

{ name:string,
 region:string,
 phoneCode:string,
 timezones:[
  {name:string,
  offset:integer,
  pos:{lat:decimal,log:decimal}
  }
 ]
}

Compress:

const compressed = JsonLight.compress(data, { type , mapping: true })
console.log(JSON.stringify(compressed, null, 2))

Output:

{
  "0": [
    {
      "1": [
        40.4165,
        -3.70256
      ],
      "_": [
        "Madrid",
        1
      ]
    },
    {
      "1": [
        35.8883,
        -5.3162
      ],
      "_": [
        "Ceuta",
        1
      ]
    },
    {
      "1": [
        28.1248,
        -15.43
      ],
      "_": [
        "Canary",
        0
      ]
    }
  ],
  "_": [
    "Spain",
    "Europe",
    "34"
  ],
  "__map": {
    "0": "timezones",
    "1": "pos"
  }
}

Decompress:

const decompressed = JsonLight.decompress(compressed, { type })
console.log(JSON.stringify(decompressed, null, 2))

Output:

{
  "name": "Spain",
  "region": "Europe",
  "phoneCode": "34",
  "timezones": [
    {
      "name": "Madrid",
      "offset": 1,
      "pos": {
        "lat": 40.4165,
        "log": -3.70256
      }
    },
    {
      "name": "Ceuta",
      "offset": 1,
      "pos": {
        "lat": 35.8883,
        "log": -5.3162
      }
    },
    {
      "name": "Canary",
      "offset": 0,
      "pos": {
        "lat": 28.1248,
        "log": -15.43
      }
    }
  ]
}

CLI

Install

npm install -g json-light 

Version:

json-light version

Type:

json-light type -i source.json

Compress:

json-light compress -i source.json -o compressed.json -s '{name:string,region:string,phoneCode:string,timezones:[{name:string,offset:integer,pos:{lat:decimal,log:decimal}}]}' 

Decompress:

json-light decompress -i compressed.json -o original.json -s '{name:string,region:string,phoneCode:string,timezones:[{name:string,offset:integer,pos:{lat:decimal,log:decimal}}]}' 

CLI examples

these examples are based on the files found in the git repository

Type

json-light type -i ./src/dev/sources/countries.json
json-light type -i ./src/dev/sources/northwind.json

Output:

[{name:string,iso3:string,iso2:string,numeric_code:string,phone_code:string,capital:string,currency:string,currency_symbol:string,tld:string,native:string,region:string,subregion:string,timezones:[{zoneName:string,gmtOffset:integer,gmtOffsetName:string,abbreviation:string,tzName:string}],translations:{kr:string,br:string,pt:string,nl:string,hr:string,fa:string,de:string,es:string,fr:string,ja:string,it:string,cn:string},latitude:string,longitude:string,emoji:string,emojiU:string,states:[{id:integer,name:string,state_code:string,latitude:string,longitude:string,type:string}]}]

{entities:[{entity:string,rows:[{id:any,name:string,description:string,contact:string,phone:string,address:string,city:string,region:string,postalCode:string,country:string,lastName:string,firstName:string,title:string,titleOfCourtesy:string,birthDate:string,hireDate:string,reportsToId:integer,homepage:string,supplierId:integer,categoryId:integer,quantity:string,price:decimal,inStock:integer,onOrder:integer,reorderLevel:integer,discontinued:boolean,customerId:string,employeeId:integer,orderDate:string,requiredDate:string,shippedDate:string,shipViaId:integer,freight:decimal,details:[{orderId:integer,productId:integer,unitPrice:decimal,quantity:integer,discount:integer}]}]}]}

Compress

json-light compress -i ./src/dev/sources/countries.json -o ./src/dev/results/countries.json -m
json-light compress -i ./src/dev/sources/northwind.json -o ./src/dev/results/northwind.json -m

Decompress

json-light decompress -i ./src/dev/results/countries.json -o ./src/dev/results/countries_original.json
json-light decompress -i ./src/dev/results/northwind.json -o ./src/dev/results/northwind_original.json

Results

[4.0K]  .
├── [4.0K]  results
│   ├── [427K]  countries.json
│   ├── [712K]  countries_original.json
│   ├── [ 43M]  customers.json
│   ├── [ 79M]  customers_original.json
│   ├── [328K]  northwind.json
│   └── [464K]  northwind_original.json
└── [4.0K]  sources
    ├── [949K]  countries.json
    ├── [154M]  customers.json
    └── [893K]  northwind.json