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-tree-view

v0.4.12

Published

A JSON Tree View Component, for browsering or editing JSON object. Fork from json-view writing by Richard Livingston.

Downloads

1,190

Readme

JSONTreeView

A simple JSON viewer with basic edit capabilities. It has styles similar to Chrome's dev tools, so it's perfect for building dev tools extensions... live example.

Install with NPM

npm i json-tree-view

Build example

./example/build.sh See ./example/build directory.

Basic usage

index.js

var JSONTreeView = require('json-tree-view');

var view = new JSONTreeView('example', {
    hello : 'world',
    doubleClick : 'me to edit',
    a : null,
    b : true,
    c : false,
    d : 1,
    e : {nested : 'object'},
    f : [1,2,3]
});

// Listen for change events
view.on('change', function(self, key, oldValue, newValue){
    console.log('change', key, oldValue, '=>', newValue);
});
view.on('rename', function(self, key, oldName, newName) {
    console.log('rename', key, oldName, '=>', newName);
});
view.on('delete', function(self, key) {
    console.log('delete', key);
});
view.on('append', function(self, key, nameOrValue, newValue) {
    console.log('append', key, nameOrValue, '=>', newValue);
});
view.on('click', function(self, key, value) {
    console.log('click', key, '=', value);
});
view.on('expand', function(self, key, value) {
    console.log('expand', key, '=', value);
});
view.on('collapse', function(self, key, value) {
    console.log('collapse', key, '=', value);
});
view.on('refresh', function(self, key, value) {
    console.log('refresh', key, '=', value);
});

// Expand recursively
view.expand(true);

view.withRootName = false;

// Inspect window.data on the console and note that it changes with edits.
window.data = view.value;

view.value.f.pop()
view.value.f.push(9)
view.value.e.a = 'aaa';
delete view.value.c;
view.refresh();

// Do not hide root.
view.alwaysShowRoot = true;

// Set readonly when filtering words automatically.
view.readonlyWhenFiltering = true;
view.filterText = 'a';

// Remove word filter by setting a false value.
view.filterText = null;

// Always show count of object or array.
view.showCountOfObjectOrArray = true;

// Cannot change the value of JSON and remove "+" and "x" buttons.
view.readonly = true;

document.getElementById('filter').addEventListener('input', function() {
    view.filterText = this.value;
});
document.getElementById('root').addEventListener('change', function() {
    view.alwaysShowRoot = !!this.checked;
});
document.getElementById('rowf').addEventListener('change', function() {
    view.readonlyWhenFiltering = !!this.checked;
});
document.getElementById('ro').addEventListener('change', function() {
    view.readonly = !!this.checked;
});
document.getElementById('sc').addEventListener('change', function () {
    view.showCountOfObjectOrArray = !!this.checked;
});

index.html - (don't forget to include the css)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JSONView Example</title>
    <link rel="stylesheet" href="devtools.css">
    <style>
      ul { user-select:none; }
    </style>
    <script src="index.js" defer></script>
</head>
<body>
<h3>Options</h3>
<ul>
  <li>
    <label for="filter">Filter: </label>
    <input type="text" id="filter" />
  </li>
  <li>
    <input type="checkbox" id="root" />
    <label for="root">Always show root</label>
  </li>
  <li>
    <input type="checkbox" id="rowf" />
    <label for="rowf">Automatically set to readonly when filtering</label>
  </li>
  <li>
    <input type="checkbox" id="ro" />
    <label for="ro">Readonly</label>
  </li>
  <li>
    <input type="checkbox" id="sc" checked />
    <label for="sc">Show count of Object or Array</label>
  </li>
</ul>
<h3>JSON</h3>
</body>
</html>