title: How to write Java Array string to Json File
body: <p>I have Java string and would like to parse it to JSON file. I first try to parse the string to an Object then to Json Object. The java string contains array/list of 2 elements. I would want to maintain that structure since its submitted to an API in that form.</p>
  <p>Content of my String looks as below:</p>
  <pre><code>[
        { &quot;foedselsdato&quot; : &quot;2012-04-29&quot;,
          &quot;individId&quot; : &quot;052804211084&quot;,
          &quot;undergruppe&quot; : &quot;KU&quot;,
          &quot;varslinger&quot; :
          { &quot;medisinering&quot; :
            [
              { &quot;merknad&quot; : &quot;&quot;,
                &quot;preparat&quot; : &quot;11 Mastipen vet Intramammarie 300 mg\/sprÃ¸yte&quot;,
                &quot;tilbakeholdelsesdato&quot; : &quot;2020-08-25&quot; },
  
              { &quot;merknad&quot; : &quot;&quot;,
                &quot;preparat&quot; : &quot;11 Penovet vet Inj vÃ¦ske, susp 300 mg\/ml&quot;,
                &quot;tilbakeholdelsesdato&quot; : &quot;2020-08-25&quot; } ] } },
  
        { &quot;foedselsdato&quot; : &quot;2017-05-19&quot;,
          &quot;individId&quot; : &quot;052820651335&quot;,
          &quot;undergruppe&quot; : &quot;KU&quot;,
          &quot;varslinger&quot; :
          { &quot;helsetilstand&quot; :
            [
              { &quot;merknad&quot; : &quot;Ole test&quot;,
                &quot;tilstand&quot; : &quot;SVAK_HALTHET&quot;,
                &quot;tiltak&quot; : &quot;EKSTRA_STROE&quot; } ] } } ]
  </code></pre>
  <p>Below is my code:</p>
  <pre><code>String Stringtojson =  Concstring;
  
  JSONParser parser = new JSONParser();
  try
  {
      Object object = parser.parse(Stringtojson);
      
      //convert Object to JSONObject
      JSONObject jsonObject3 = (JSONObject)object;
      try {
          FileWriter file = new FileWriter(&quot;F:\myjson.json&quot;);
          file.write(jsonObject3.toJSONString());
          file.close();
          } catch (IOException e) {                                        
          e.printStackTrace();
          }
      
  
  }
  catch(Exception e)
  {
      e.printStackTrace();
  }
                                  
  </code></pre>