title: Convert JSON object with duplicate keys to JSON array
body: <p>I have a JSON string that I get from a database which contains repeated keys. I want to remove the repeated keys by combining their values into an array. </p>
  
  <p>For example</p>
  
  <p>Input</p>
  
  <pre><code>{
  "a":"b",
  "c":"d",
  "c":"e",
  "f":"g"
  }
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>{
  "a":"b",
  "c":["d","e"],
  "f":"g"
  }
  </code></pre>
  
  <p>The actual data is a large file that may be nested. I will not know ahead of time what or how many pairs there are.</p>
  
  <p>I need to use Java for this. org.json throws an exception because of the repeated keys, gson can parse the string but each repeated key overwrites the last one. I need to keep all the data.</p>
  
  <p>If possible, I'd like to do this without editing any library code</p>