title: How to use Groovy JsonOutput.toJson with data encoded with UTF-8?
body: <p>I have a file with UTF-8 encoding.</p>
  
  <p>I write a groovy script to load a file with a JSON structure, modify it and save it:</p>
  
  <pre><code>def originPreviewFilePath = "./xxx.json"
  
  //target the file
  def originFile = new File(originPreviewFilePath) 
  
  //load the UTF8 data file as a JSON structure
  def originPreview = new JsonSlurper().parse(originFile,'UTF-8')
  
  //Here is my own code to modify originPreview
  
   //Convert the structure to JSON Text
  def resultPreviewJson = JsonOutput.toJson(originPreview) 
  
  //Beautify JSON Text (Indent)
  def finalFileData = JsonOutput.prettyPrint(resultPreviewJson) 
  
  //save the JSONText
  new File(resultPreviewFilePath).write(finalFileData, 'UTF-8') 
  </code></pre>
  
  <p>The problem is that <code>JsonOutput.toJson</code> transforms UTF-8 data to UNICODE. I don't understand why <code>JsonSlurper().parse</code> can use UTF-8 but not <code>JsonOutput.toJson</code>?</p>
  
  <p>How to have <code>JsonOutput.toJson</code> use UTF-8? I need to have the exact inverse of <code>JsonSlurper().parse</code></p>