Coder Social home page Coder Social logo

simple-json-viewer's Introduction

simple-json-viewer

The simple, lightweight JSON viewer for the browser.

Features:

  • fuzzy search (with regex support)
  • folding
  • keyboard-only friendly
  • highlighting
  • lightweight
  • hackable (src/index.js)
  • browser support okay (not that I care about IE users any more)
    • Unprefixed flexbox is probably the limiting factor

Screenshots

Usage

<script src="dist/simple-json-viewer.js"></script>

<div id="json-viewer-container"></div>

<script>
  var container = document.querySelector('#json-viewer-container');

  // var json = '{"jsonArgCanBeJsonString": true}';
  var json = { jsonArgCanBeJsonObject: true };

  var options = {
    fontFamily: '"Fira Mono", monospace',
    colors: ['gray', '#090', '#c00', 'purple', '#00c', '#ccc', '#333', 'yellow', 'rgb(240,240,240)']
  };

  var viewer = createJSONViewer(container, json, options);

  viewer.changeJSON({ youCanAlsoChangeTheJSON: 'after the viewer is created' });
</script>

methods

  • JSONViewer.changeJSON(json<String|Object>, path<Array> {optional, default: []})
    var viewer = createJSONViewer(el, json, opts);
    
    setTimeout(function () {
      // without path, replaces all of the json
      viewer.changeJSON({ "array": [ { "i-have-been-modified": false } ] });
    }, 1000);
    
    setTimeout(function () {
      // with path, replaces specific part of the json
      viewer.changeJSON(true, ["array", 0, "i-have-been-modified"]);
    }, 2000);

options

  • fontFamily {default: 'monospace'}
    If you want to use a custom font (you'll have to load it yourself).
  • colors {default: ['#999', '#090', '#c00', '#c0c', '#00c', '#ccc', '#333', '#ff0', '#eee']}
    An array of 9 CSS colors as strings. To see what each one does, look here (numbers before vmax corresponds to the index, so color: 3vmax means color: #c0c with defaults)
  • onValueClick {default: none}
    onValueClick allows you to pass a handler when a value is clicked. It will be the closest ancestor that is either a key-value pair from an object, or an item from an array.
    var json = {
      "someArray": [
        "clickMe"
      ]
    };
    
    var viewer = createJSONViewer(el, json, {
      onValueClick: function (valueOfClicked, pathToClicked, element) {
        console.log(valueOfClicked); // "clickMe"
        console.log(pathToClicked);  // ["someArray", 0]
        console.log(element);        // div.json-viewer-array-value
      }
    });

Finally

If you want to contribute, create a pull request :D

Also, it's a small library of a few hundred lines, so if it's missing something why not modify it.

:thumbs-up:

simple-json-viewer's People

Contributors

tbjgolden avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

simple-json-viewer's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.