The second parameter of `JSON.stringify` is a custom `replacer`. By specifying that, you could have dodged the hairy spacing logic and gotten away with cleaner logic.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify