title: How to convert json file to excel file in java
body: <p>I,m given a problem to convert <code>JSON</code> file to excel file, in short to convert <code>JSON</code> data to excel data. Tried mapping <code>JSON</code> keys and values but can't do it.</p>
  
  <p>Tried mapping <code>JSON</code> keys and values but can't do it. I have already used apache POI api.</p>
  
  <pre><code>public class jsontoexcel {
  
      public static void main(String[] args) throws IOException,JSONException {
          jsontoexcel json4=new jsontoexcel();
          JSONObject json=json4.ReadJson();
          JSONArray array =new JSONArray();
          JSONObject rowjson=json.getJSONArray("rows").getJSONObject(0);
  
          XSSFWorkbook workbook=new XSSFWorkbook();
          XSSFSheet sheet=workbook.createSheet("Company Details");
  
          int len=rowjson.length();
          String[] RowArr=new String[len];
          Iterator&lt;String&gt; keys = rowjson.keys();
          int i=0;
          while(keys.hasNext())
          {
              RowArr[i]=keys.next();
              System.out.print("key:"+keys);
              i++;
          }
          List&lt;String&gt; slist= new ArrayList&lt;String&gt;();
          slist=json.get(rowjson.toString(keys));
  
           FileOutputStream out=new FileOutputStream(new File("C:\\code\\eclipse\\jsontoexcel\\src\\output.xlsx"));
  
           createHeaderRow(sheet, RowArr);
           workbook.write(out);
           out.close();
  
  
  
        //  Map&lt;String,Object&gt; map=new Map&lt;String,Object&gt;();      
  
      }
  
      public static void createHeaderRow(XSSFSheet sheet, String[] RowArr)
      {
          Row row=sheet.createRow(0);
          for(int i=0;i&lt;RowArr.length-1;i++)
          {
              Cell cellTitle=row.createCell(i+1);
              String cellVal=RowArr[i];
              System.out.print("Cell data" + cellVal);
          }
      }
  }
  </code></pre>
  
  <p>I expect the output to be stored in an excel file. The headers are getting printed but not the values.</p>