Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
json-light
Advanced tools
Json Light is a json compressor, generating a new simplified json file from a schema definition.
The schema 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.
get schema from json data
get a compressed json
decompress a previously compressed json getting the original json
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 } }
]
}
Schema:
const schema = JsonLight.schema(data)
console.log(schema)
Output:
{ name:string,
region:string,
phoneCode:string,
timezones:[
{name:string,
offset:integer,
pos:{lat:decimal,log:decimal}
}
]
}
Compress:
const compressed = JsonLight.compress(data, schema)
console.log(JSON.stringify(compressed, null, 2))
Output:
{
"_": [
"Spain",
"Europe",
"34"
],
"timezones": [
{
"_": [
"Madrid",
1
],
"pos": [
40.4165,
-3.70256
]
},
{
"_": [
"Ceuta",
1
],
"pos": [
35.8883,
-5.3162
]
},
{
"_": [
"Canary",
0
],
"pos": [
28.1248,
-15.43
]
}
]
}
Decompress:
const decompressed = JsonLight.decompress(compressed, schema)
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
}
}
]
}
Install
npm install -g json-light
Version:
json-light version
Schema:
json-light schema -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}}]}'
these examples are based on the files found in the git repository
json-light schema -i ./src/dev/sources/countries.json
json-light schema -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}]}]}]}
json-light compress -i ./src/dev/sources/countries.json -o ./src/dev/results/countries.json
json-light compress -i ./src/dev/sources/northwind.json -o ./src/dev/results/northwind.json
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
[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
FAQs
Allow to extend yaml or json files configuration
We found that json-light demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.