Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
jsonlish stringify

jsonlines and similar formats where each payload is stored as unindented JSON chunks divided by newlines are great for complex systems.

My application is more to aid in exploring large JSON files and copying/pasting, chunks in the editor, therefore made this small JSON stringifier that breaks the 1st level of arrays and objects with newlines,while returning valid JSON.

The placement of commas is intentional. This way one can find the item, right, shift+end, copy.


function jsonlishStringify(data) {
if (data instanceof Array) {
return '[\n' + => JSON.stringify(o)).join('\n,') + '\n]';
if (typeof data === 'object') {
return (
'{\n' +
.map(([k, v]) => {
return '"' + k + '":' + JSON.stringify(v);
.join('\n,') +
return JSON.stringify(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment