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 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-color-stream

v1.2.0

Published

A stream parser for pretty printing for JSON

Downloads

96

Readme

JSON Color Stream

A stream parser for pretty printing for JSON!

A no-nonsense, low-dependency, streaming API for converting nasty and fragmented JSON strings into beautiful, canonicalized outputs

  • Accepts either full JSON strings or serial chunk, following a "parse-as-you-go" paradigm:
    • Large JSON blobs? No problem! The minimal memory overhead has your back!
    • Don't wait for your whole JSON string to come in, let the parser give you the fragments now!
  • Fully configurable output format (either from the command line or a configuration file): pick your "canonical form" and make all strings obey!
  • Integrated colorization: never let your eyes bleed again!
  • Fully asynchronous backend: make the event loop work for you!

Get it today, on npm!

# Add to your library
npm install json-color-stream

# Or, install globally so you can use the CLI
npm install -g json-color-stream

Basic Usage

See the full API for all the gory details, but here's a quick primer:

const { JSONStream } = require("json-color-stream");

// Statically parse
console.log(JSONStream.parse(`{ "a": 1 }`));

let js;

// Handle non-piped input
js = new JSONStream();
js.on("data", (string) => console.log(string));
js.end(`{ "a": 1 }`);

// Handle piped (fragmented) input
js = new JSONStream();
js.on("data", (string) => process.stdout.write(string));
js.write(`{ "a"`);
js.write(`: 1 }`);
js.end();

CLI Usage

If you globally installed the package (or locally, then just use npx jcs), then you can do all this on the command line too!

# Show the help menu
jcs --help

# Format JSON strings
jcs '{"a": 1}'

# Can pipe to stdin too! Just use the "-" argument
curl -s https://api.github.com/users/jonathanvanschenck/repos | jcs -

# Can turn off colors, and quote suppression, so that your eyes can bleed
jcs --colorize-mode 0 --quote-suppression-mode 0 '{"a": 1}'

# Okay, maybe its just that you are piping to a file or your terminal doesn't support joy and beauty,
#  in that case, you might want to make turn on character escaping too:
jcs \
  --colorize-mode 0 \
  --quote-suppression-mode 0 \
  --escape-whitespace 1 \
  --escape-unicode 1 \
  '{"a": 1, ["\n", "\u00f6"]}'

# Or maybe you just want to cannonicalize the output, in which case you can turn everything off:
#  like pretty formats, etc. 
jcs \
  --indent "" \
  --EOL "" \
  --colon ":" \
  --colorize-mode 0 \
  --quote-suppression-mode 0 \
  --escape-whitespace 1 \
  --escape-unicode 1 \
  '{"a": 1, ["\n", "\u00f6"]}'

If you don't like any of the defaults, you can edit them in $HOME/.config/jcs/config.json, which are just the Renderer's constructor options:

Manual Installation

Make sure you have node.js installed on your system

Make sure the index file is executable

chmod +x cli.js

Simulink the index file to some folder in your path, e.g.:

cd /usr/local/bin
ln -s /path/to/cli.js jcs

TODOs

  • Add configuration management tools to the cli
  • Add some convenient overrides to cli, for things like "--cannonicalize"
  • Add non-composite starts for JSON strings?
  • Clean up error reporting, for the possibility of error handling
  • Allow parser resets
  • Add filtering, like some subset of jq?