
Security News
Next.js Patches Critical Middleware Vulnerability (CVE-2025-29927)
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
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.
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
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.