{"id":22650654,"url":"https://github.com/data7expressions/json-light","last_synced_at":"2025-03-29T07:22:19.090Z","repository":{"id":151936786,"uuid":"624071932","full_name":"data7expressions/json-light","owner":"data7expressions","description":"Json Light","archived":false,"fork":false,"pushed_at":"2024-03-11T18:53:40.000Z","size":1471,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-17T10:47:49.757Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/data7expressions.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-04-05T17:26:51.000Z","updated_at":"2024-04-14T22:42:00.101Z","dependencies_parsed_at":null,"dependency_job_id":"833a30fb-9f7e-4675-9d68-45e4891153da","html_url":"https://github.com/data7expressions/json-light","commit_stats":null,"previous_names":["expr-solver/json-light","data7expressions/json-light"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2Fjson-light","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2Fjson-light/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2Fjson-light/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2Fjson-light/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/data7expressions","download_url":"https://codeload.github.com/data7expressions/json-light/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246151583,"owners_count":20731631,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-09T08:36:17.590Z","updated_at":"2025-03-29T07:22:19.069Z","avatar_url":"https://github.com/data7expressions.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Json Light\n\n\u003eJson Light is a json compressor, generating a new simplified json file from a type definition.\n\u003e\n\u003eThe type can be written by us or generated by the library itself.\n\u003e\n\u003eJson Light extracts the property tags from a json object and stores the values in an array.\n\u003e\n\n## Features\n\n- Compress json generating a new valid json\n- Allows to get type from json data\n- 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\n- CLI\n\n## Methods\n\n### .type(data:any)\n\nget type from json data\n\n- Params:\n  - data : json data\n\n### .compress(data:any, type?:string)\n\nget a compressed json\n\n- Params:\n  - data : json data\n  - type : type (optional)\n  - mapping : replace names of properties for key and save mapping (optional)\n\n### .decompress(data:any, type?:string)\n\ndecompress a previously compressed json getting the original json\n\n- Params:\n  - data : json data\n  - type : type (optional)\n\n## Quick start\n\n```typescript\nimport { JsonLight } from 'json-light'\n\nconst data = {\n name: 'Spain',\n region: 'Europe',\n phoneCode: '34',\n timezones: [\n  { name: 'Madrid', offset: 1, pos: { lat: 40.4165, log: -3.70256 } },\n  { name: 'Ceuta', offset: 1, pos: { lat: 35.8883, log: -5.3162 } },\n  { name: 'Canary', offset: 0, pos: { lat: 28.1248, log: -15.43 } }\n ]\n}\n```\n\nGet Type:\n\n```typescript\nconst type = JsonLight.type(data)\nconsole.log(type)\n```\n\nOutput:\n\n```txt\n{ name:string,\n region:string,\n phoneCode:string,\n timezones:[\n  {name:string,\n  offset:integer,\n  pos:{lat:decimal,log:decimal}\n  }\n ]\n}\n```\n\nCompress:\n\n```typescript\nconst compressed = JsonLight.compress(data, { type , mapping: true })\nconsole.log(JSON.stringify(compressed, null, 2))\n```\n\nOutput:\n\n```javascript\n{\n  \"0\": [\n    {\n      \"1\": [\n        40.4165,\n        -3.70256\n      ],\n      \"_\": [\n        \"Madrid\",\n        1\n      ]\n    },\n    {\n      \"1\": [\n        35.8883,\n        -5.3162\n      ],\n      \"_\": [\n        \"Ceuta\",\n        1\n      ]\n    },\n    {\n      \"1\": [\n        28.1248,\n        -15.43\n      ],\n      \"_\": [\n        \"Canary\",\n        0\n      ]\n    }\n  ],\n  \"_\": [\n    \"Spain\",\n    \"Europe\",\n    \"34\"\n  ],\n  \"__map\": {\n    \"0\": \"timezones\",\n    \"1\": \"pos\"\n  }\n}\n```\n\nDecompress:\n\n```typescript\nconst decompressed = JsonLight.decompress(compressed, { type })\nconsole.log(JSON.stringify(decompressed, null, 2))\n```\n\nOutput:\n\n```javascript\n{\n  \"name\": \"Spain\",\n  \"region\": \"Europe\",\n  \"phoneCode\": \"34\",\n  \"timezones\": [\n    {\n      \"name\": \"Madrid\",\n      \"offset\": 1,\n      \"pos\": {\n        \"lat\": 40.4165,\n        \"log\": -3.70256\n      }\n    },\n    {\n      \"name\": \"Ceuta\",\n      \"offset\": 1,\n      \"pos\": {\n        \"lat\": 35.8883,\n        \"log\": -5.3162\n      }\n    },\n    {\n      \"name\": \"Canary\",\n      \"offset\": 0,\n      \"pos\": {\n        \"lat\": 28.1248,\n        \"log\": -15.43\n      }\n    }\n  ]\n}\n```\n\n## CLI\n\nInstall\n\n```sh\nnpm install -g json-light \n```\n\nVersion:\n\n```sh\njson-light version\n```\n\nType:\n\n```sh\njson-light type -i source.json\n```\n\nCompress:\n\n```sh\njson-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}}]}' \n```\n\nDecompress:\n\n```sh\njson-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}}]}' \n```\n\n## CLI examples\n\nthese examples are based on the files found in the git repository\n\n### Type\n\n```sh\njson-light type -i ./src/dev/sources/countries.json\njson-light type -i ./src/dev/sources/northwind.json\n```\n\nOutput:\n\n```javascript\n[{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}]}]\n\n{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}]}]}]}\n```\n\n### Compress\n\n```sh\njson-light compress -i ./src/dev/sources/countries.json -o ./src/dev/results/countries.json -m\njson-light compress -i ./src/dev/sources/northwind.json -o ./src/dev/results/northwind.json -m\n```\n\n### Decompress\n\n```sh\njson-light decompress -i ./src/dev/results/countries.json -o ./src/dev/results/countries_original.json\njson-light decompress -i ./src/dev/results/northwind.json -o ./src/dev/results/northwind_original.json\n\n\n```\n\n### Results\n\n```sh\n[4.0K]  .\n├── [4.0K]  results\n│   ├── [427K]  countries.json\n│   ├── [712K]  countries_original.json\n│   ├── [ 43M]  customers.json\n│   ├── [ 79M]  customers_original.json\n│   ├── [328K]  northwind.json\n│   └── [464K]  northwind_original.json\n└── [4.0K]  sources\n    ├── [949K]  countries.json\n    ├── [154M]  customers.json\n    └── [893K]  northwind.json\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdata7expressions%2Fjson-light","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdata7expressions%2Fjson-light","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdata7expressions%2Fjson-light/lists"}