warfares / pretty-json Goto Github PK
View Code? Open in Web Editor NEWSimple library to render/format a JS obj to an HTML view.
License: MIT License
Simple library to render/format a JS obj to an HTML view.
License: MIT License
It would be nice to have support for node.js.
Hey, great library.
I had a problem where a project had used underscore _.templateSettings to change the default behavior.
Problem is that in your library you do your templates based on the default settings, so if someone overrides it, it wont work.
A minor improvement would be for this library to specify its template settings directly.
_.template(templateString, [data], [settings])
Just create an obj with the default settings
{
evaluate : /<%([\s\S]+?)%>/g,
interpolate : /<%=([\s\S]+?)%>/g,
escape : /<%-([\s\S]+?)%>/g
}
(I already fixed in my project by using the solution above, to not interfere with your library, but a library shouldnt depend on that to work)
The text within a string leaf value is not HTML escaped when rendered, which leaves this open to scripting attacks, and minor UI failures like so:
{
"name": "John Doe <[email protected]>"
}
Which renders to:
{
name : "John Doe "
}
One could also do something malicious like:
{
"name": "John Doe <script>alert('I am bad!')</script>"
}
Which will execute the arbitrary script. This can be fixed simply by changing the Leaf underscore template to escape the data with a <%-data%><
instead of <%=data%>
.
Any chance you could add support for displaying the keys in sorted order?
Perhaps by adding support for a callback so the caller can handle various sort cases?
For example, it'd be great to add a node and bold it above others.
My specific case includes making a sample JSON payload, and I would like to bold what's mandatory and what's not.
Hi there,
First of all, this library is awesome and it has no competitive libs. Well done mate!
I ran into a case where I needed to collapse all nodes including the root one. Sadly the root node is not collapsible, because this condition
if(this.level != 1)
this.hide();
Would it be possible to add an option, something like collapseRootNode: true/false?
The reason, why it would be awesome is when you have a table (grid) and one of the columns is json, it's not possible to collapse it, so the row column is huge instead of just "{....}".
Thanks in advance!
The live demo page gives a 404 error.
For instance with the demo link, input:
{
"timestamp": 1511399821249614354
}
result:
{
timestamp : 1511399821249614300
}
Currently there is not event
when the parsing has been completed. For very large JSON
file this could be helpful. Thank you.
Hi,
It appears that in your minified version, the license text from "/build/license.txt" is included in the file, but your project says that it's licensed under the MIT License.
Can you please clarify this (and place a license in the header of all your files?).
Thank you.
It would be very nice if there was an option to enable quotes around elements, this is especially useful when pasting this json back into a strict json parser.
eg.
{
"node": "value"
}
do we have npm package?
if json have null value:
"wife": {
"name":null,
"age": 28
}
as result you print:
wife : {
name : ,
age : 28
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.