
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
js-object-pretty-print
Advanced tools
Serializes a javascript object to a printable string. String is formatted to be used in either pure text environments, like a console log or in HTML or to create a JSON output.
Serializes a javascript object to a printable string. String is formatted to be used in a pure text environments, like a console log, as an HTML output, or to create a JSON string.
npm install js-object-pretty-print
var pretty = require('js-object-pretty-print').pretty,
address,
value;
function onAnother(foo, bar) {
var lola;
lola = foo + bar;
return lola;
}
address = {
'street': 'Callejon de las ranas 128',
'city': 'Falfurrias',
'state':
'Texas',
'zip': '88888-9999'
};
value = {
'name': 'Damaso Infanzon Manzo',
'address': address,
'favorites': {
'music': ['Mozart', 'Beethoven', 'The Beatles'],
'authors': ['John Grisham', 'Isaac Asimov', 'P.L. Travers'],
'books': [ 'Pelican Brief', 'I, Robot', 'Mary Poppins' ]
},
'dates': [ new Date(), new Date("05/25/1954") ],
'numbers': [ 10, 883, 521 ],
'boolean': [ true, false, false, false ],
'isObject': true,
'isDuck': false,
'onWhatever': function (foo, bar) {
var lola;
lola = foo + bar;
return lola;
},
'onAnother': onAnother
};
address.value = value;
console.log(pretty(value));
It is also possible to use a minified version of the code
...
var prettyMin = require('js0object-pretty-print/index-min.js').pretty;
...
Either the full or the minified versions render the same. Both are unit tested with Mocha and Chai
Function pretty accepts four arguments:
pretty(object, indentSize, outputTo, fullFunction);
Is the javascript object to serialize. If no object is present the function will return a string with an error.
Number of spaces in a one level indent. Default 4
String to determine the formatting of the output. One of "PRINT", "HTML" or "JSON". This argument is case insensitive. Default value is "PRINT"
A boolean to determine to expand all the text of a function or to display only the signature. The default value is to display only the signature, that is the word function followed by the function name, if any, followed by the arguments of the function in parenthesis.
{
...
onWhatever: "function (foo, bar)",
onAnother: "function onAnother(foo, bar)"
}
{
...
onWhatever: function (foo, bar) {
var lola;
lola = foo + bar;
return lola;
},
onAnother: function onAnother(foo, bar) {
var lola;
lola = foo + bar;
return lola;
}
}
Notice that the program does not attempt to pretty print the function. It is rendered as written.
Expected behavior
Sometimes some objects have circular references. This will can cause a heap overflow if not dealt properly. The code now detects circular references and stop inspecting the object
Objects and properties with value null or undefined are now properly reported.
FAQs
Serializes a javascript object to a printable string. String is formatted to be used in either pure text environments, like a console log or in HTML or to create a JSON output.
The npm package js-object-pretty-print receives a total of 11,169 weekly downloads. As such, js-object-pretty-print popularity was classified as popular.
We found that js-object-pretty-print demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.