Convert JSON to human readable HTML

Overview

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

Comments
  • npm

    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.

    opened by jyniybinc 9
  • old jsdom version

    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.

    opened by jyniybinc 6
  • Enahcements

    Enahcements

    Option to hide Array Index (Issue #5)

    Pass showArrayIndex: true / false to hide or show array indices in the output If not set, it is assumed to be true

    Option to output hyperlinks in the HTML output (Issue #4)

    Create "hyperlinks" key in the options to enable this in output

    hyperlinks : { enable : true, keys: ['url'], // Keys which will be output as links target : '_blank' // 'target' attribute of a }

    Code changes

    JS

    _format will get two more params - the options object and also parentKey to set the context. This is useful when we are parsing arrays and need to know what the parent-key was. For now, useful to identify if we are parsing list of hyperlinks. Could be useful for other things in future.

    validateOptions methods will be used to validate the options object passed-in. Any new validations can be inside this (ex validateHyperlinkOptions and validateArrayIndexOption)

    linkNode functions is like scn. Creates a a-node(hyperlink) and appends child node to that.

    CSS

    New classes for hyperlinks

    opened by VikramN 5
  • Rails Assets component error

    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

    opened by tomkuk 4
  • Adds bower compatibility

    Adds bower compatibility

    Json.human.js does not support Bower, with this pull requests everyone will be able to add it to their projects just by doing bower install json-human.

    Once this is merged, the following needs to be ran :

    bower register json-human https://github.com/marianoguerra/json.human.js.git

    opened by Esya 4
  • Date and

    Date and "empty objects" that are not objects.

    Add support for Date objects and "empty objects" that are not objects. Uses obj.toString() to display the object.

    Also convert "CONSTANTS" to be bitmask-compatible and replace switch statement with if statement in order to be able to use bitmasks.

    opened by joar 3
  • PrettyPrint.js

    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

    opened by randyburden 3
  • Impossible to distinguish empty arrays from empty objects

    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 ( { } ).

    opened by VictorBlomberg 3
  • customize inline styles

    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?

    opened by jyniybinc 1
  • Customize Boolean Display

    Customize Boolean Display

    Fix for Issue #3

    Users can display bool as text, image or both They can customize the text display for true & false as well

    Things changed

    Added default icons for true false Modified CSS a bit, users can customize true & false font color Used google font to prettify the output Updated demo page Users can play with options in demo page as well

    TODO

    Please update the demo page [http://marianoguerra.github.io/json.human.js/]

    opened by VikramN 1
  • Nodejs support

    Nodejs support

    Hello, I was charmed by your json to table demo. I wanted to get it to work in nodejs with npm instead of bower.

    It seems I got it to work with just this much (see changes). I've managed to write away your table output to an html file, using outerHTML.

    So I created a package.json file for you, so anyone can use this in nodejs.

    You could publish it on npm. 'json-human' is still available.

    Also, the demo page still works, so I guess this merge should not break anything.

    opened by nickyout 1
  • Componification of json.human.js

    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?

    opened by dbrrt 1
  • Add icons representing types

    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
    enhancement 
    opened by kazagistar 0
  • Add button or someway to show the original json

    Add button or someway to show the original json

    Sometimes I need to copy the json to move it to another place. I would like to see the formatted json by default but be able to change to a view that shows me the original json.

    enhancement 
    opened by javierdallamore 0
  • Chrome Extension?

    Chrome Extension?

    Would you be interested in creating a Chrome Extension with this functionality?

    For example, when you visit http://graph.facebook.com/facebook, it would parse it with this library.

    I am currently using the JSON Formatter (https://github.com/callumlocke/json-formatter) and it is great. JSON Formatter could be used as a model to incorporate this library into it's own extension.

    enhancement 
    opened by ElijahLynn 3
Releases(0.1.1)
⏱ Simple Alpine.js plugin to display the human-readable distance between a date and now.

⏱ Alpine TimeAgo ⏱ An Alpine.js plugin to return the distance between a given date and now in words (like "3 months ago", "about 2 hours ago" or "in a

Marc Reichel 47 Dec 22, 2022
Enhanced interval features for Node.js, such as promisified interval and human readable time parsing.

Interval-next Interval-next is a package that extends Javascript's built-in setInterval() capabilities. You have a plain and promisified interval meth

Snowy 5 Jul 28, 2022
parses human-readable strings for JavaScript's Temporal API

?? temporal-parse What is the temporal-parse? Temporal is the next generation of JavaScript's standard Date API. It's currently proposed to TC39 (see:

Eser Ozvataf 22 Jan 2, 2023
Svelte component to display time distances in a human readable format.

Time Distance Display time distances in a human readable format. Based on date-fns Updates every 60 seconds View demo Usage Install package: pnpm i -D

Joshua Nussbaum 8 Nov 2, 2022
JCS (JSON Canonicalization Scheme), JSON digests, and JSON Merkle hashes

JSON Hash This package contains the following JSON utilties for Deno: digest.ts provides cryptographic hash digests of JSON trees. It guarantee that d

Hong Minhee (洪 民憙) 13 Sep 2, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de créer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
Pretty-print-json - 🦋 Pretty-print JSON data into HTML to indent and colorize (written in TypeScript)

pretty-print-json Pretty-print JSON data into HTML to indent and colorize (written in TypeScript) 1) Try It Out Interactive online tool to format JSON

Center Key 87 Dec 30, 2022
✏️ A small jQuery extension to turn a static HTML table into an editable one. For quickly populating a small table with JSON data, letting the user modify it with validation, and then getting JSON data back out.

jquery-editable-table A small jQuery extension to turn an HTML table editable for fast data entry and validation Demo ?? https://jsfiddle.net/torrobin

Tor 7 Jul 31, 2022
Convert Your Kindle highlight & Note to Markdown/JSON

kindle-highlight-to-markdown Convert Your Kindle highlight & Note to Markdown/JSON Install Install with npm: npm install kindle-highlight-to-markdown

azu 15 Dec 31, 2022
jsonrawtoxlsx is library to convert json raw (array) into xlsx file

Welcome to jsonrawtoxlsx ?? ✨ What is jsonrawtoxlsx? jsonrawtoxlsx is library to convert json raw (array) into xlsx file ⚡️ Installation using npm npm

M Arie Syukron 17 Dec 23, 2022
javascript library to convert a list of objects to a nested json output format, depending on the names in the list

formToNestedJson javascript "library" to convert a list of objects to a nested json output format, depending on the names in the list Basic usage Give

null 2 Aug 2, 2021
Render readable & responsive tables in the terminal

terminal-columns Readable tables for the terminal. Tables can be automatically responsive! Features Content wrapped to fit column width Column widths

hiroki osame 28 Oct 28, 2022
⛲ Sort import declarations into a pleasing and readable cascade.

⛲ eslint-plugin-cascading-imports This plugin allows to automatically enforce a visual "cascading" order for import declarations. Imports in each bloc

Florent 1 Jan 20, 2022
A compiled-away, type-safe, readable RegExp alternative

?? magic-regexp A compiled-away, type-safe, readable RegExp alternative ✨ Changelog ?? Documentation ▶️ Online playground Features Runtime is zero-dep

Daniel Roe 1.5k Jan 8, 2023
Library for readable and manageable Next.js middleware

?? Next Compose Middleware This is a library for building Next.js complex middleware declaratively. You can create highly readable and manageable midd

Ibuki Kaji 14 Dec 19, 2022
Minimalistic configuration for TS to only extend JS with types. No TS features, no bundling. Readable maintainable code after compilation.

ts-guideline Minimalistic configuration for TS to only extend JS with types. No TS-scpecific features, no bundling. Readable maintainable code after c

Georg Oldenburger 41 Dec 22, 2022
Wrap zod validation errors in user-friendly readable messages

zod-validation-error Wrap zod validation errors in user-friendly readable messages. Features User-friendly readable messages, configurable via options

Causaly 70 Dec 23, 2022
💡 Providing equitable access to human useable Web3 data.

?? Providing equitable access to human useable Web3 data. Unidata The beauty of Web3 is that everyone owns their data, but accessing and displaying ow

DIYgod 264 Jan 2, 2023
💡 Providing easy access to human-friendly Web3 data.

?? Providing easy access to human friendly Web3 data. Unidata Docs The beauty of Web3 is that everyone owns their data, but accessing and displaying o

Natural Selection Labs 263 Dec 29, 2022