Giter Site home page Giter Site logo

json.human.js's Introduction

json.human.js: Json Formatting for Human Beings

A small library to convert a JSON object into a human readable HTML representation that is easy to style for different purposes.

Who?

Mariano Guerra

Why?

At Event Fabric we need to display JSON to people from all technical levels without being to technical but also without losing information about the underlying JSON object.

How?

you can see js/demo.js in this repo for an example or use it live at the project page

var node = JsonHuman.format(input);
output.appendChild(node);

Additional options parameter can be supplied

var input = {
      "url" : [
            "www.google.com",
            "www.google.com",
            {
              "x" : "x-direction",
              "y" : "y-direction",
              "url" : "www.google.com"
            }
      ]
};

var node = JsonHuman.format(input, {
    // Show or hide Array-Indices in the output
    showArrayIndex: true,

    // Hyperlinks Option
    // Enable <a> tag in the output html based on object keys
    // Supports only strings and arrays
    hyperlinks : {
        enable : true,
        keys: ['url'],          // Keys which will be output as links
        target : '_blank'       // 'target' attribute of a
    },

    // Options for displaying bool
    bool : {
        // Show text? And what text for true & false?
        showText : true,
        text : {
            true : "Yes",
            false : "No"
        },

        // Show image? And which images (urls)?
        showImage : true,
        img : {
            true : 'css/true.png',
            false : 'css/false.png'
        }
    }
});

To install it, if you're using Bower you can just run:

bower install json-human --save

Alternatives

License?

MIT

json.human.js's People

Contributors

ajanuary avatar anaran avatar benroy73 avatar esya avatar iceman81 avatar joar avatar marianoguerra avatar nickyout avatar vikramn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

json.human.js's Issues

Retain multiple whitespaces

I thought I just throw this in: if strings are represented as-is and special stuff like \n or &gt; stays raw as well, it would make sense to stop browser from displaying, for example, " padded " as " padded ". I'm thinking about <pre>.

customize inline styles

This is exactly what I have been looking for and it works great but sadly I would like to send the table via email and external styles aren't really supported. Would it be possible to have a config parameter like styles: { th: 'border: 1px solid black', td: 'some css' } and then embed that into the table as inline style tags?
Is json.human.js appropriate for emails?

Add icons representing types

Consider adding icons to represent type more semantically? This will solve confusion about which type something is, without causing too much confusion for users.

Here are some ideas from the Bootstrap Glyphicons (which was on hand as some examples):

  • string: icon-comment
  • number: icon-calculator
  • object: icon-folder-open
  • array: icon-list
  • true/false: icon-check
  • null: icon-asterisk

What about using JSONEditor in view mode?

This may be off-topic, but reading your motivation for json.human.js:

At Event Fabric we need to display JSON to people from all technical levels without being to technical but also without losing information about the underlying JSON object.

I was thinking you could use my jsoneditor component in view mode as well (try this example). Comes with nice coloring and expandable trees.

Just an idea...

Update bower.json

Update bower.json main to
"main":[
"./css/json.human.css",
"./src/json.human.js"
]

npm

Would it be possible to host json-human on npm? npm is also for clientside libraries and would make installing easier. You would also support node users.

old jsdom version

Could you please update the jsdom version? I can't install with npm because it throws an error. Newer jsdom versions don't require contextify anymore.

Componification of json.human.js

It would be nice to have like a HOC Component that Renders the JSON under sub components using modern framework/ui libraries such as vue, react, ember etc...

Do you think that I can be a feature of this library, or a sort of wrapper would be required to make this feasible?

PrettyPrint.js

Just making you all aware of prettyprint.js which basically does the same thing as this library albeit a bit more colorful. I love that there are now more options for formatting JSON into a more human readable format. Keep up the good work!

prettyprint.js: https://github.com/padolsey/prettyPrint.js

Rails Assets component error

Hi @marianoguerra,

I tried to get json.human.js working with rails-assets but it fails with the following message.

json-human has no versions defined. Please create an issue in component's repository.

The problem is the lack of version tag. Could you please create a tag with current revision of the package using semver format? It could be 0.0.1, or anything you suggest.

Here is the component import page to check it working: https://rails-assets.org/components/new

Reverse functionality

As an enhancement - It would be great to build an object using human readable inputs, and have it return a valid JSON object

Impossible to distinguish empty arrays from empty objects

Since the readme states that the goal is to display JSON:

without losing information about the underlying JSON object

I think it should be considered a bug that there is no way at all to distinguish an empty array ( [ ] ) from an empty object ( { } ).

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.