1.2.2 • Published 5 years ago
sort-json-by-key v1.2.2
sort-json-by-key
This script will help you parse JSON file by key and sort it to separate files like key.json. :scroll:
Example
Imagine you have a file, named city-list.json, which contain an array of objects like this:
[
{
"id": 3036216,
"name": "Auga",
"country": "FR"
},
{
"id":2509475,
"name":"Villatobas",
"country":"ES"
},
{
"id":3127817,
"name":"Bordalba",
"country":"ES"
},
{
"id":6295630,
"name":"Earth"
}
]... and we need to get separate files by key's value.
FR.json
[
{
"id": 3036216,
"name": "Auga",
"country": "FR"
}
]ES.json
[
{
"id":2509475,
"name":"Villatobas",
"country":"ES"
},
{
"id":3127817,
"name":"Bordalba",
"country":"ES"
}
]For additional this script will create two files
_.json for not found values
[
{
"id":6295630,
"name":"Earth"
}
]_keyList.json
["FR","ES",null]Installation
npm i -g sort-json-by-keyUsage
List of all commands
sort-json-by-key --helpBasic usage. Flag --output is optional
sort-json-by-key --file-path <filePath> --key <key> Extended usage
sort-json-by-key --file-path <filePath> --key <key> --output <outputDir>Important
:warning: Flag --output is not required and if it won't be passed, script will execute all outputs in current directory.
License
ISC © 2021 VanoKoliesnik