title: How to remove an element from a .json file?
body: <p>I have a JSON file: "data.json" containing a JSONArray of about 600 objects that have attributes: alias, telephone, type,  building and title. And I'm trying to remove all of the alias and telephone attributes from the objects in the array.</p>
  
  <p>Here's a sample:</p>
  
  <pre><code>[
    {
      "Title": "7 Eleven",
      "Alias": "Seven Eleven",
      "Building": "7 Eleven"
    },
    {
      "Title": "Adaptive Computing Research Lab",
      "Alias": "acrl",
      "Type": "Faculty",
      "Building": "COM1"
    },
    {
      "Title": "Alcove.Asian Restaurant Bar",
      "Building": "University Cultural Centre"
    },
    {
      "Title": "Algorithms Research Lab",
      "Alias": "arl",
      "Type": "Faculty",
      "Building": "COM1"
    }
  ]
  </code></pre>
  
  <p>I understand that this is a JsonArray so I have to parse it is as a JsonArray type instead of a JsonObject so the parsing is not the problem. But when I use this code</p>
  
  <pre><code>import javax.json.*;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  
  public static void main(String args[]) throws FileNotFoundException {
  
      JsonReader reader = Json.createReader(new FileReader("data.json"));
      JsonArray jsonArray = (JsonArray) reader.read();
  
      for (int i = 0; i &lt; jsonArray.size(); i++) {
  
          JsonObject o = (JsonObject) jsonArray.get(i);
  
          if (o.containsKey("Alias"))
              o.remove("Alias");
  
          if (o.containsKey("Telephone"))
              o.remove("Telephone");
  
          System.out.println(jsonArray);
      }
  
  }
  </code></pre>
  
  <p>I'm having this error</p>
  
  <p><code>Exception in thread "main" java.lang.UnsupportedOperationException
      at java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$1.remove(Collections.java:1664)
      at java.util.AbstractMap.remove(AbstractMap.java:254)
      at JSONEditor.main(JSONEditor.java:20)
  </code></p>
  
  <p>I don't understand why it is Unmodifiable.</p>
  
  <p>So far, I've looked through many other similar questions and answers on StackOverflow and documentation that suggest that what I'm trying to do is possible but I still don't understand why this isn't working out for me.</p>