title: Add an linkedhashmap to an Array
body: <p>I'm new with java and I have this doubt. I'm making a custom response in a Rest API and I want to introduce an array of errors with this format.</p>
  
  <pre><code>"http_code": 500,
  "status": "INTERNAL_SERVER_ERROR",
  "info": "Internal Server Error",
  "errors": [
        {
          "code": 500,
          "message": "Internal Server Error"
        }
      ]
  </code></pre>
  
  <p>But I don't know how to do it on JAVA. My code until now it's something like this:</p>
  
  <pre><code> LinkedHashMap&lt;String, Object&gt; arrayObj = new LinkedHashMap&lt;String, Object&gt;();
   arrayObj.put("code", 500);
   arrayObj.put("message", "Internal Server Error");
  
   List&lt;&gt; errors = new ArrayList&lt;&gt;(); //This part is where I don't know what to do
  // Should I put a LinkedHashMap as output result?
  
  
  LinkedHashMap&lt;String, Object&gt; map = new LinkedHashMap&lt;String, Object&gt;();
  map.put("http_code", 500);
  map.put("status", "INTERNAL_SERVER_ERROR");
  map.put("info", "Internal Server Error");
  map.put("errors", errors); // in this part would introduce the array of objects
  
  </code></pre>
  
  <p>I am not able to know how to do it, because if I put Linkedhasmap as a result, there is no method that returns the object as I want. Thanks in advance. </p>
  
  <p><strong>EDIT 2:</strong> </p>
  
  <p>Finally, I resolved the puzzle. Here's the code:</p>
  
  <pre><code> JSONArray errorArray = new JSONArray();
   JSONObject errorsObject= new JSONObject();
   errorsObject.put("code", 500);
   errorsObject.put("message", "Internal Server Error");
   errorArray.put(errorsObject.toMap());
  
          LinkedHashMap&lt;String, Object&gt; map = new LinkedHashMap&lt;String, Object&gt;();
  
   map.put("http_code", 500);
   map.put("status", "INTERNAL_SERVER_ERROR"));
   map.put("info", info);
   map.put("errors", errorArray.toList());
  
  </code></pre>