sort-json-by-key

1.2.2 • Public • Published

sort-json-by-key

This script will help you parse JSON file by key and sort it to separate files like [key].json. 📜

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

⚠️ Flag --output is not required and if it won't be passed, script will execute all outputs in current directory.

License

ISC © 2021 VanoKoliesnik

Readme

Keywords

Package Sidebar

Install

npm i sort-json-by-key

Weekly Downloads

0

Version

1.2.2

License

ISC

Unpacked Size

6.26 kB

Total Files

5

Last publish

Collaborators

  • vanokoliesnik