1.2.2 • Published 3 years ago

sort-json-by-key v1.2.2

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

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

Usage

List of all commands

sort-json-by-key --help

Basic 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

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago