List<Section> sectionList = new ArrayList<Section>(sections.keySet());
Collections.sort(sectionList);
int sectionCount = sectionList.size();
for (Section section : sectionList) {
Map children = (Map) sections.get(section);
LocaleManager localeManager = LocaleManager.lookup();
String sectionTitle = StringUtil.replaceAll(localeManager.localize(section.getTitle()).toString(), "\\", "\\\\");
sectionTitle = StringUtil.replaceAll(sectionTitle, "'", "\\'");
result += "['" + sectionTitle + "', '" + section.getId() + "_" + section.getPosition() + "_" + (sectionCount - 1) + "'";
if (children != null && !children.isEmpty()) {
result += ", ";