For anyone wanting to do this in Javascript, here's a wrapper for JSON.stringify
that can do it for any kind of spacing:
const toPrettyJSONString = (value, replacer = null, space = "\t") =>
JSON.stringify(value, replacer, space).replace(new RegExp("(\n\\s*)(.*?:) ([\\[{])(?=\n)", "g"), "$1$2$1$3");