title: Node JS, logging JSON with ansi code
body: <p>I'm simply trying to log JSON with some ANSI styling codes, in Node.js, here is the code, with several examples:</p>
  
  <pre><code>let s = chalk.green('Hello World')
  let o = {s} // or {s: s}
  
  console.log(s)
  console.log(o)
  console.log(o.s)
  console.log(JSON.stringify(o))
  </code></pre>
  
  <p><em>(Note: <code>chalk</code> is just like <code>colors</code>)</em></p>
  
  <p>But the formatting is escaped when logging an object or stringifying it. Is there any way to prevent it?<br>
  Result:
  <a href="https://i.stack.imgur.com/M4ynK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M4ynK.png" alt="enter image description here"></a></p>
  
  <p>So it's just like logging <code>\u001b[32mHello World\u001b[39m</code> and <code>\\u001b[32mHello World\\u001b[39m</code> (with double <code>\</code>)</p>
  
  <p>PS: I know there are hundred of workarounds but I stumbled on that problem and I've been looking for a simple solution. Thx!</p>