Another way to achieve this is simply serialize object to JSON string with any popular JSON library such as Jackson, Gson and so on.
First, construct a nested map of objects as follows:
Map<String, Object> teamEventMap = new HashMap<>();
teamEventMap.put("3050", Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8));
teamEventMap.put("3052", Arrays.asList(1, 2, 8));
teamEventMap.put("3054", Arrays.asList(4));
Map<String, Object> configMap = new HashMap<>();
configMap.put("TeamEvents", teamEventMap);
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("Configs", configMap);
Then just leverage JSON library for serialization without directly operating JSON objects:
// By using Jackson
ObjectMapper objectMapper = new ObjectMapper();
System.out.println(objectMapper.writeValueAsString(resultMap));
// By using Gson
Gson gson = new Gson();
System.out.println(gson.toJson(resultMap));
Both two JSON libraries produce the same output as expected:
{"Configs":{"TeamEvents":{"3054":[4],"3052":[1,2,8],"3050":[1,2,3,4,5,6,7,8]}}}
One of the benefits for this way resides it is easy to switch to another JSON library without much code change.