Skip to content

jirokun/sort-json-by-object-key

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sort-json-by-object-key

Sort JSON by key and don't change the value.

If you use jq or other commands to sort JSON by object key, the representation of the values will change, so I created this tool to sort JSON by object key without changing the representation of the values.

Example

Here's a sample json.

$ cat test.json
{
  "abc": 3e7,
  "def": {
    "xyz": 1.0,
    "uvw": "abc"
  }
}

sort by jq command with --sort-keys option. representation is changed.

$ jq --sort-keys < test.json
{
  "abc": 30000000,
  "def": {
    "uvw": "abc",
    "xyz": 1
  }
}

sort by this cli. representation is not changed.

$ sortjson < test.json
{
  "abc": 3e7,
  "def": {
    "uvw": "abc",
    "xyz": 1.0
  }
}

About

Sort JSON by key and don't change the value.

Resources

Stars

Watchers

Forks

Packages

No packages published