npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

komb

v0.0.2

Published

Sort and tidy up some JSON

Downloads

5

Readme

komb

A tiny Babashka utility for sorting JSON. It reads JSON content, sorts object keys and (array) values alphanumerically and pretty-prints the result.

Features

  • Sorts nested JSON objects and arrays
  • Reads JSON from a file or from stdin
  • Semantic sort preserves order of array elements, can be disabled
  • Pretty-printing, can be disabled
  • Runs locally/offline by Node.js or GraalVM
  • Returns bash exit code on success/error

Motivation

I was searching for an offline tool, but only thing I've found was jsonabc. This utility does almost the same but it's implemented using a sane language 😃. It also fixes some issues of jsonabc like sorting numbers.

This tool reads JSON from a file or from stdin if no argument provided. By default it will sort semantically, keeping order of array elements as is and pretty-print the result.

The basic idea was to have a handy tool to compare JSON files. With additional CLI options it's also possible to sort JSON files without loosing semantic order.

komb uses proper shell exit codes to communicate successful or failed execution.

See usage examples down below.

Command Line Interface

komb - sort JSON & pretty-print

Usage: komb [options] [path]

Reads content of a JSON file from *stdin* if no path provided.

Options:
      --[no-]semantic  true  Enable to preserve order of array elements
      --[no-]pretty    true  Pretty-print the result
  -h, --help                 Print this help.

Arguments:
  path - path to JSON file

Installation

komb supports two different runtimes: Native GraalVM and Node.js. The user can decide which flavor suits better.

Run on Node.js

Any modern Node.js version should be sufficient. Ensure node/npm/npx are available before proceed next. komb is written using Clojure and it brings nbb as a dependency to interpret code with it, so no additional libraries besides Node.js itself are required.

Try komb out without installation via

npx komb some-json-file.json

# or provide JSON directly
cat <<'JSON' | npx komb --no-semantic
{
  "alias": "bb",
  "full-name": "Babashka",
  "author": "borkdude",
  "unordered-numbers": [2, 5, 1, 2, 9]
}
JSON

or install it from public NPM.

npm install komb

Verify installation succeeded:

komb --help

Please note this utility has no JS interface and therefore it cannot be used from JS code as a library.

Run on GraalVM

This scenario is probably for Clojure (savvy) people. Currently there is no pre-build binary available for this tool, but it can be installed from source.

Make sure you've installed Babashka. You probably also will need a recent Java, cause Babashka uses Java-based tools for dependency management.

Clone the repository

git clone [email protected]:and-z/komb.git
cd komb

Assume executing following commands from the local project directory.

(Optional) Install using bbin to local path

The most convenient way to use this utility is to install it as a tool using bbin.

With bbin in place you can install komb from the local git repository:

bb install

It's also easily uninstalled with:

bb uninstall

Make sure to uninstall old version before installing a more recent one.

Tip: List available tasks with bb tasks.

(Optional) Use as Babashka task

It's also possible to use this utility without installation. The API should be consistent.

List available tasks
bb tasks
Sort some JSON file using Babashka task
bb komb test/it/zimpel/komb/unsorted.json
Sort some JSON from stdin using Babashka task
cat test/it/zimpel/komb/unsorted.json | bb komb

Usage examples

Once komb is on your path it can be executed providing a path to a JSON file:

Sort using default behaviour:

komb test/it/zimpel/komb/unsorted.json

If no file is provided komb reads JSON content from stdin:

cat test/it/zimpel/komb/unsorted.json | komb

Sometimes it's handy to sort everything (including arrays), e.g. to compare JSON payloads visually:

cat <<'JSON' | komb --no-semantic --no-pretty
{
  "a": [99,3,4,22,33,99]
}
JSON

Output:

{"a":[3,4,22,33,99,99]}

Use komb with code editor (Emacs/Spacemacs/etc)

Having a programmable editor is actually pretty nice. I'm not an Emacs specialist at all, but with some guidance from the excellent article "Executing Shell Commands in Emacs" by Mickey Petersen I was able to easily embed komb into my workflow. In this example I'm using Spacemacs but the idea should be transferrable to other editors as well.

I've defined my custom elisp function like shown below:

(defun sort-json ()
  "Sorts and pretty-prints JSON using `komb` Babashka tool"
  (interactive)
  (shell-command-on-region
   ;; beginning and end of buffer
   (point-min)
   (point-max)
   ;; command and param
   "komb"
   ;; output buffer
   (current-buffer)
   ;; replace?
   t
   ;; name of the error buffer
   "*komb Error Buffer*"
   ;; show error buffer
   t))

For more convenience I've also defined a custom key binding for JSON major mode:

(defun dotspacemacs/user-config()
  ; some existing user configuration
  ; ...
  (spacemacs/set-leader-keys-for-major-mode 'json-mode "o=" 'sort-json)

With this small adjustments in place sorting JSON files became a breeze:

  • Open unsorted JSON file in Emacs buffer
  • Press , o =
  • Profit

Development

It is possible to start a standard Clojure, Babashka or nbb REPL to play with source code. Nothing special to mention here.

Run tests

bb test:bb

Startup time

Here are some numbers (in descending order) to give an idea of how quick/slow different versions may run. The measurements are not scientific and don't pretent to be a valid benchmark. I executed different variants of starting komb and wrapped the commands with time on my linux dev machine.

| runtime | note | cmd | time | |---------|------|-----|------------| | nodejs | not installed | npx komb test/it/zimpel/komb/unsorted.json | 0,37s user 0,05s system 72% cpu 0,581 total | | nodejs | not installed | npx nbb -m it.zimpel.komb.main test/it/zimpel/komb/unsorted.json | 0,27s user 0,08s system 132% cpu 0,262 total | | nodejs | not installed | nbb --classpath src -m it.zimpel.komb.main test/it/zimpel/komb/unsorted.json | 0,15s user 0,02s system 131% cpu 0,127 total | | nodejs | npm install -g komb | komb test/it/zimpel/komb/unsorted.json | 0,14s user 0,03s system 132% cpu 0,128 total | | graalvm | not installed | bb komb test/it/zimpel/komb/unsorted.json | 0,01s user 0,02s system 90% cpu 0,029 total | | graalvm | bb install | komb test/it/zimpel/komb/unsorted.json | 0,01s user 0,03s system 94% cpu 0,040 total |

not installed means komb is not installed as a tool via npm install for Node.js flavor or bb install for GraalVM flavor. When properly installed there is no performance penalty for dynamic lookup like in case of npx.