title: Convert list of strings into JSON with Groovy
body: <p>I have a list of Strings like so:</p>
  
  <pre><code>List&lt;String&gt; errors = []
  errors &lt;&lt; 'Your password was bad.'
  errors &lt;&lt; 'Your feet smell.'
  errors &lt;&lt; 'I am having a bad day.'
  </code></pre>
  
  <p>That I would like converted (via Groovy/3rd party libs) into JSON:</p>
  
  <pre><code>{
      [
          "Your password was bad.",
          "Your feet smell.",
          "I am having a bad day."
      ]
  }
  </code></pre>
  
  <p>My best attempt thus far is <strong>nasty</strong> and I expect there is a much quicker/leaner/more efficient way of doing this:</p>
  
  <pre><code>static String errorsToJSON(List&lt;String&gt; errors) {
      StringBuilder sb = new StringBuilder()
      sb.append('{ ')
      List&lt;String&gt; errorJsons = []
      errors.each {
          errorJsons &lt;&lt; '\"${it}\"'
      }
  
      // https://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Joiner.html
      List&lt;String&gt; list = Joiner.on(',').join(errorJsons)
      list.each {
          sb.append(it)
      }
      sb.append(' }')
  
      sb.toString()
  }
  </code></pre>