I have this json file I downloaded online:
{
\"price\": 1,
\"empty\": [
0,
0,
0,
0,
0
],
\"lowValue\": 0,
\"highValue\": 0
},
and I
Use a JSON library like Jackson:
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
public class JsonDelete {
public static void main(String[] args) throws IOException {
ObjectMapper mapper = new ObjectMapper();
String json = "{\"key\":\"value\",\"empty\":[]}";
ObjectNode node = (ObjectNode) mapper.readTree(json);
node.remove("empty");
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(node));
}
}
Outputs:
{
"key" : "value"
}