How to add a String Array in a JSON object?
You're getting an error because your last line is invalid Java.
school.put("name", new JSONArray("[\"john\", \"mat\", \"jason\", \"matthew\"]"));
Little improper approach suggested by Tom. Optimised code would be:
ArrayList<String> list = new ArrayList<String>();
list.add("john");
list.add("mat");
list.add("jason");
list.add("matthew");
JSONObject school = new JSONObject();
school.put("class","4");
school.put("name", new JSONArray(list));