Skip to content

Instantly share code, notes, and snippets.

@szkrd
Last active July 22, 2017 12:49
Show Gist options
  • Save szkrd/dbaba0ec19f3fa7a1f6921339d26c3fb to your computer and use it in GitHub Desktop.
Save szkrd/dbaba0ec19f3fa7a1f6921339d26c3fb to your computer and use it in GitHub Desktop.
prettify json for spec console logs
// dumb
console.log('>>>\n' + JSON.stringify(instance.state, null, 2).replace(/ "([a-zA-Z_]*)": /g, ' $1: ').replace(/ "([^"]*)"(,?)/g, ' \'$1\'$2') + '\n<<<');
// dumber
console.log('>>>\n' + JSON.stringify(result, null, 2).replace(/"/g, '\'').replace(/(\s+)'([^']*)'(: )/g, '$1$2$3')) + '\n<<<')
// copy-paste to console
copy(JSON.stringify(temp1, null, 2).replace(/"/g, '\'').replace(/(\s+)'([^']*)'(: )/g, '$1$2$3')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment