0.0.2 • Published 3 years ago

@skoropletov/json-stringify-with-sorting v0.0.2

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

json-stringify-with-sorting

Sorting object keys in a given order in the JSON.stringify result. Recursively

import JSWS from "@skoropletov/json-stringify-with-sorting";

const jsws = new JSWS([
  'firstKey',
  'secondKey',
  'thirdKey',
  'fourthKey',
]);

console.log(jsws.stringify({
  fourthKey: true,
  justAnotherKey: "I'll be displayed after all 4 of them", 
  secondKey: 1,
  thirdKey: 100,
  
  yetAnotherKey: "Alex says hi",
  firstKey: {
    thirdKey: 100,
    yetAnotherKey: "Alex says hi",
    secondKey: {
      firstKey: "I'm a first string",
      yetAnotherKey: "Alex says hi",
      fourthKey: true,
      secondKey: "I'm a second string",
      thirdKey: 100,
    },
    firstKey: "first string in an object here"
  }
}));
0.0.2

3 years ago

0.0.1

3 years ago