So this is your code (I edited your post, please accept it):
JSONObject obj = new JSONObject();
obj.put("name", "ABC");
obj.put("user","fl9f03fe24a2c4a4b51a4d75");
datanew = (JSONObject) obj.get("data");
datanew.put("details", "component");
datanew.put("Key", "123");
datanew.put("region","server-23");
Your JSON object obj
is new and empty, it doesn't contain anything. So you can't get("data")
before you put("data")
first. Try this:
JSONObject obj = new JSONObject();
obj.put("name", "ABC");
obj.put("user","fl9f03fe24a2c4a4b51a4d75");
JSONObject datanew = new JSONObject();
datanew.put("details", "component");
datanew.put("Key", "123");
datanew.put("region","server-23");
obj.put("data", datanew);