JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 435
  • Score
    100M100P100Q96389F
  • License ISC

A module to sort a JSON file.

Package Exports

  • sort-nested-json

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sort-nested-json) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

sort-nested-json

You can use sort-nested-json to sort an json array.

Install

npm install --save sort-nested-json

Usage

Here is an basic example of using sort-nested-json.

import sorter from 'sort-nested-json';

let list = [{  
                id: 1,
                firstname: "John",
                lastname: "Smith"
            },
            {  
                id: 2,
                firstname: "Jane",
                lastname: "Wilson"
            },
            {  
                id: 3,
                firstname: "Peter",
                lastname: "Brown"
            }]

list = sorter.sort(list).desc("firsname")

console.log(list)

list = sorter.sort(list).asc("firsname")

console.log(list)

Here is an example of using sort-nested-json with a nested sort.

import sorter from 'sort-nested-json';

let list = [{  
                id: 1,
                details:{
                    firstname: "John",
                    lastname: "Smith"
                } 
            },
            {  
                id: 2,
                details:{                
                    firstname: "Jane",
                    lastname: "Wilson"
                }
            },
            {  
                id: 3,
                details:{                
                    firstname: "Peter",
                    lastname: "Brown"
                }
            }]

list = sorter.sort(list).desc("id")

console.log(list)            

list = sorter.sort(list).desc("details.firsname")

console.log(list)

list = sorter.sort(list).asc("details.firsname")

console.log(list)

License

ISC