Coder Social home page Coder Social logo

yesmeck / jquery-jsonview Goto Github PK

View Code? Open in Web Editor NEW
492.0 25.0 157.0 107 KB

[UNMAINTAINED]View JSON in a more readable format

Home Page: http://yesmeck.github.io/jquery-jsonview/

CoffeeScript 79.19% CSS 7.50% HTML 13.31%
jquery-jsonview jquery-plugin json-viewer

jquery-jsonview's Introduction

jQuery JSONView

Formats & syntax highlights JSON.

Port of Ben Hollis's JSONView extension for Firefox: http://jsonview.com

Live demo

Usage

Example

var json = {"hey": "guy","anumber": 243,"anobject": {"whoa": "nuts","anarray": [1,2,"thr<h1>ee"], "more":"stuff"},"awesome": true,"bogus": false,"meaning": null, "japanese":"明日がある。", "link": "http://jsonview.com", "notLink": "http://jsonview.com is great"};

$(function() {
  $("#json").JSONView(json);
  // with options
  $("#json-collasped").JSONView(json, { collapsed: true });
});

Options

jQuery JSONView can be configured using the following options.

  • collapsed - Collapse all nodes when rendering first time, default is false.
  • nl2br - Convert new line to <br> in String, default is false.
  • recursive_collapser - Collapse nodes recursively, default is false.
  • escape - Escape HTML in key, default is true.
  • strict - In strict mode, invalid JSON value type will throw a error, default is false.

API

jQuery JSONView provide following methods to allow you control JSON nodes, all methods below accept a level argument to perform action on the specify node.

  • jQuery#JSONView('collapse', [level]) - Collapse nodes.
  • jQuery#JSONView('expand', [level]) - Expand nodes.
  • jQuery#JSONView('toggle', [level]) - Toggle nodes.

Licence

MIT

jquery-jsonview's People

Contributors

aartek avatar adamtootle avatar hyandell avatar ohadperry avatar ovilia avatar tenbits avatar xiyanhu avatar yesmeck 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

jquery-jsonview's Issues

Issue with collapse/expand/toggle functions

You can reproduce it even your sample page:

  1. Open page http://blog.yesmeck.com/jquery-jsonview/
  2. Click button "Toggle level 1"
  3. Now click sign '-' near property 'anobject'

You will notice error in console:
TypeError: Argument 1 of Node.removeChild is not an object.
on line:

target.parentNode.removeChild(ellipsis);

Problem exists in this part of code:

if (args[1] != null) {
    level = args[1];
    return $this.find(".jsonview .level" + level)[method]();
} else {
    return $this.find('.jsonview > ul > li > .collapsible')[method]();
}

It happens because you just hide or show collapsible area only.
But sign '-' was not changed to '+', no ellipces was added, correct css classes, etc.

Instead of using standard jQuery functions here should be used existing "Collapser" object, which can hide or show collapsible area in a proper way.

Feature Request

Any particular reason why html Keys are not supported ? here
It can be solved simply by changing (this.jsString(prop)) to prop.
Let me know this is ok, and i'll create a pull request.

Feature request: data for node via Ajax call

It would be great to be able to have children/data for a node loaded via an Ajax call that is only made when the node is expanded. This way, for larger documents, the entire document doesn't have to be loaded from the start.

publish your lib on CDNJS ?

Hey yesmeck !

Your JSONView lib is great and I'm sure I'm not the only one to think that you should publish it on cdnjs.cloudflare.com for easier use !

You'll also get a huge new audience as beleive me I searched there is no equivalent on CDNJS yet !

Congrats on the work !

Bower Version

Hey Yesmeck,

please provide this within bower!

Regards
Markus

Downstream Compilation Issue

Howdy 👋

I'm including this in an application that has clean-css as part of its build process. When building a production build the build process get clean-css to "throw on warning" which is designed to prevent any issues with CSS unknowingly getting through to the production build (I guess).

It has started failing on jquery-jsonview because the css file has a sourceMappingUrl definition at the bottom of it but there is no sourcemap actually provided https://github.com/yesmeck/jquery-jsonview/blob/master/dist/jquery.jsonview.css#L56

I don't know if it's easy in your build process to just remove this comment line but if you could point me in the right direction I might be able to take a look with a PR if I get a chance.

Expand/Collapse

when calling jsonView('collapse'), although it collapses the first level nodes, the inner level are kept in tact, there should be a way to collapse all (including the inner/higher levels )

发现bug一枚

var jsonFormatter = new JSONFormatter;
// Covert, and catch exceptions on failure
if( Object.prototype.toString.call(jsonObj) !== '[object Object]' ) {
jsonObj = JSON.parse(jsonObj);
}
var outputDoc = jsonFormatter.jsonToHTML(jsonObj);

如果jsonObj是个Array呢?

Very slow on large jsons.

Should not create inner logic if collapsed:true is given, should initiate inner logic only when tree is collapsed. (only on click)

Suggestion to support pretty view of multiline string

Hi,

Currently multiline string displays as singleline with encoded symbols \r\n.

In my project I fixed it by enhancing JSON formatter encoder:

JSONFormatter.prototype.htmlEncode

I just added additional replacement:

.replace(/\\r?\\n/g, "<br/>")

What do you think about having such logic in this plugin by default?

Feature request: API to return clean JSON object

Currently if you get the content of the DOM element processed by JSONView it includes the - (dash) for toggling nodes. Would be really useful to get back the clean object though, say, JSONView('json').

Add feature to call collapse outside

It will be a good feature to collapse code from outside, for example by button. And abiltiy to choose nested level for collapse will be awesome.

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.