title: Read a Json File. Add an additional field depending on one of the field values. Write back Json
body: <p>I have a json file that looks like  </p>
  
  <pre><code>[{"field1":Value1, 
    "field2":value2,
       "field3_find":[value3,value4],
        "field4_find":{"sub1":subval1,"sub2":subvalue2}
     }
  
  {"field1":Value5,
      "field2":value6,
       "field3_find":[value7,value8],
        "field4_find":{"sub1":subval3,"sub2":subvalue3}
     }
  ]
  </code></pre>
  
  <p>I want to read the Json. Find a particular key value pair. Once a matching field is found , create a new field depending on the value of this field. Write back Json.</p>
  
  <pre><code>import org.json.simple.JSONArray;
  import org.json.simple.JSONObject;
  import org.json.simple.parser.JSONParser;
  import org.json.simple.parser.ParseException;
  import java.util.HashSet;
  import java.util.LinkedHashMap;
  import java.util.LinkedList;
  import java.util.List;
  import java.util.Map;
  import java.io.FileReader;
  JSONParser parser = new JSONParser(); 
  ArrayList&lt;LinkedHashMap&lt; String, JSONObject&gt;&gt; AllRows;
  AllRows = (JSONArray) parser.parse(new FileReader(InputFile));  
  JSONArray New_rows =new JSONArray(); 
  LinkedList&lt;String&gt; FieldNameAnotation=new LinkedList&lt;String&gt;();
           FieldNameAnotation.add(new String("field3_find"));
           FieldNameAnotation.add(new String("field4_find"));
  
          try {
              for(LinkedHashMap&lt;String,JSONObject&gt; map : AllRows){
                  JSONObject  extend_row=new JSONObject();  
                  for (Map.Entry&lt;String, JSONObject&gt; entry : map.entrySet()) {
                      if ((FieldNameAnotation).contains(entry.getKey()))
                      {
                      newvalue1=process1(entry.getKey());
                       newvalue2=process2(entry.getKey());// call a function process to get this value
                          extend_row.put(newvalue1,newvalue2);
                      } 
                  }
                  extend_row.putAll(map);
                  New_rows.add(extend_row);  
             }
  
              }catch (Exception e) {
                  System.err.println(e);
                  System.exit(0);
              }
  </code></pre>
  
  <p>However this gives an error
   org.json.simple.JSONObject cannot be cast to java.util.LinkedHashMap.   </p>
  
  <p>I know that it is because the way I have read the JSON .It is read as an array of JSON objects, But I do not how to read it as</p>
  
  <pre><code>ArrayList&lt;LinkedHashMap&lt; String, JSONObject&gt;&gt;
  </code></pre>