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

sonj-review

v0.6.1

Published

Extensible JSON Viewer

Downloads

55

Readme

sonj-review / json-viewer

npm npm version GitHub Workflow Status (branch)

Yet another json viewer lib.

Features

  • View any size of JSON as long your browser can parse/load it
  • Vanilla javascript (no additional libs required)
  • Built-in plugins
  • Extensible
  • Easy to adjust CSS

Demo

https://maxwroc.github.io/sonj-review/

Initialization

let plugins = [];
let jsonViewer = new SonjReview.JsonViewer(data, "NameOfTheRootNode", plugins);
jsonViewer.render("container-id");

Plugins

Note: plugin order matters - please be aware of it when initializing the json viewer (use the order as listed above/below)

Auto expand

By default JSON nodes are rendered collapsed. This plugin alows you to change it. You can specify depth for which nodes should be rendered open.

// root node and it's children will be rendered open
const autoExpandPlugin = SonjReview.plugins.autoExpand(2);

image

Search

Allows you to find a string in the JSON regardless if it is in the property name or value.

const searchPlugin = SonjReview.plugins.search(
    data, {
        // whether to turn on/off case-sensitive search
        caseSensitive: false
    });

const searchInput = document.getElementById("search-box");
searchInput.addEventListener("keyup", evt => evt.keyCode == 13 && searchPlugin.query(searchInput.value));

Groups

Limit the number of rendered child nodes. This way your browser won't stuck trying to render very big object. Properties or elements which won't be rendered are available in expandable groups.

// limit number of rendered child nodes to 10 (and then group by 10)
const groupsPlugin = SonjReview.plugins.propertyGroups(10);

image

Teaser

Displays additional info next to the collapsed node. You can control whether the number of elements (in case of arrays) or properties (in case of objects) should be shown. You can specify as well property names which values should be shown.

// root node and it's children will be rendered open
const teaserPlugin = SonjReview.plugins.propertyTeaser({ 
    properties: { 
        // list of the property names (their values will be shown whenever they exist)
        names: ["fname", "sname", "email"], 
        // limit of the number of properties to show 
        // (so you can specify longer prioritized list above but show only few of them found)
        maxCount: 2,
        // whether to print property name next to the value
        printNames: false,
        // max length of the single value
        maxValueLength: 20,
    },
    // max length of the total teaser length
    maxTotalLenght: 40,
    // whether to display counts (of array items or properties)
    showCounts: true,
}));;

image

Truncate

If you know that your JSON may contain long values/strings this plugin will help you.

const truncatePlugin = SonjReview.plugins.truncate({ 
    // max length for property name
    maxNameLength: 20,
    // max length for property value
    maxValueLength: 40,
    // whether to show full length info pill
    showLengthPill: true, 
    // whether to make info pill clickable (showing full, not truncated value)
    enableClickToExpand: true,
})

image

Actions menu

Handy menu allowing you to do various actions. You can easily add your custom ones.

// default menu items (copy name/value, copy formatted JSON)
const menuPlugin = SonjReview.plugins.propertyMenu();

image

Default menu items

  • copyName - Copies property name to clippord
  • copyValue - Copies property value to clipboard (in case of the object it converts it to JSON string)
  • copyFormattedValue - Copies formatted JSON value (this option is available only for object value types)

Converting JSON string to object - menu item

image

This menu item has to be added manually (it is not a part of the default menu items set). It appears only when value looks like a JSON object.

const menuItems = SonjReview.plugins.propertyMenu.items;
const menuPlugin = SonjReview.plugins.propertyMenu([
    menuItems.parseJsonValue, // menu item for converting JSON strings
    menuItems.copyName,
    menuItems.copyValue,
]

Sort menu item

Sorts values (in case of arrays) or properties (in case of objects). Sorting twice does the reverse/descending sort.

This menu item has to be added manually.

const menuItems = SonjReview.plugins.propertyMenu.items;
const menuPlugin = SonjReview.plugins.propertyMenu([
    menuItems.sortProperties, // sorting menu item
    menuItems.copyName,
    menuItems.copyValue,
]

Custom menu item definition example

const copyFormattedValue: IPropertyMenuItem = {
    text: "Copy formatted JSON",
    isHidden: context => !context.node.isExpandable,
    onClick: context => {
        navigator.clipboard.writeText(
            context.node.isExpandable ? 
                JSON.stringify(context.node.data, null, 2) : 
                context.node.data);
    }
};

Initialization with custom menu item example

const menuPlugin = SonjReview.plugins.propertyMenu([
    // using one of the default menu items
    SonjReview.plugins.propertyMenu.items.copyName,
    // your custom menu item
    myCustomMenuItem,
    // using one of the default menu items
    SonjReview.plugins.propertyMenu.items.copyFormattedValue,
]);

CDN

Development

This component is still under development so please be aware that there might be breaking changes in the next releases!

Feedback

Like it? Star it!

If something doesn't work or you have any suggestions how to improve it please create an issue on github.