private JSONArray buildJson() {
        JSONArray json = new JSONArray();
        if (!initialized || entityIds.isEmpty()) {
            return json;
        }
        int i = 0, size = entityIds.size();
        for (String entityID : entityIds) {
            try {
                JSONObject entityObj = new JSONObject();
                JSONArray dispArr = new JSONArray();
                entityObj.accumulate("entityID", entityID);
                if (idpMap.containsKey(entityID)) {
                    Map<String, String> dispNames = idpMap.get(entityID);
                    List<String> orderedLang = getOrderedLangList(dispNames);
                    int orgIdx = 0, orgSize = orderedLang.size();
                    if (orderedLang.isEmpty()) {
                        String name;
                        try {
                            name = entityID.substring(0, entityID.indexOf("/", 9));
                        } catch (Exception ex) {
                            name = entityID;
                        }
                        JSONObject dispObj = new JSONObject();
                        dispObj.accumulate("value", name);
                        dispObj.accumulate("lang", "en");
                        dispArr.put(dispObj);
                    } else {
                        for (String lang : orderedLang) {
                            JSONObject dispObj = new JSONObject();
                            dispObj.accumulate("value", dispNames.get(lang));
                            dispObj.accumulate("lang", lang);
                            dispArr.put(dispObj);
                        }
                    }
                }
                json.put(entityObj);
                entityObj.put("DisplayNames", dispArr);
            } catch (JSONException ex) {
                Logger.getLogger(MetaData.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return json;
    }