private static JSONObject flattenEntityList()

in source/src/main/java/com/amazonaws/comprehend/esproxy/lambda/processor/operations/DetectEntities.java [91:106]


    private static JSONObject flattenEntityList(@NonNull final List<Entity> entityList) {
        JSONObject flattenedEntityObject = new JSONObject();
        for (Entity entity : entityList) {
            try {
                // If the entity type exists, add the new entity to the JSONArray, otherwise create a new JSONObject
                if (flattenedEntityObject.has(entity.getType())) {
                    flattenedEntityObject.getJSONArray(entity.getType()).put(new JSONObject(entity));
                } else {
                    flattenedEntityObject.put(entity.getType(), Collections.singletonList((new JSONObject(entity))));
                }
            } catch (JSONException e) {
                return null;
            }
        }
        return flattenedEntityObject;
    }