Я успешно удалил элемент с этим кодом:
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
class SimpleJson {
public static void main(String[] args) throws IOException {
JSONObject jObject = (JSONObject) JSONValue.parse(json);
jObject.remove("MYID3");
System.out.println(jObject);
try (FileWriter writer = new FileWriter(new File("/path/result2.json"))) {
jObject.writeJSONString(writer);
}
// java 11
// Files.writeString(Path.of("/path/dir1", "result.json"), jObject.toJSONString());
}
...
}
Зависимость: com.googlecode.json-simple json-simple 1.1.1
Вывод :
{
"MYID": {
"task": "aufgabe",
"user": "name",
"status": "true"
},
"MYID2": {
"task": "aufgabe2",
"user": "name2",
"status": "false"
}
}