How To iterate over map in HTL(sightly) Component

Sample Code Snippet

HTL(Sightly) Component Snippet

<div data-sly-use.mapIterator="MapIterator">
 <!--/*  Get value of  key */-->
<div> Value of Key - 'key1' - ${mapIterator.mapItems['key1']}</div
<!--/*  Iterate over map */-->
<ul data-sly-list=${mapIterator.mapItems}>
<li>${item} - ${mapIterator.mapItems[item]}</li>
  </ul>
  <!--/*Iterate over key set*/ -->
    <ul data-sly-list.key=${mapIterator.mapItems.keySet}>
  <li>${key}</li>
    </ul>
</div>

Java Snippet

import com.adobe.cq.sightly.WCMUsePojo;
import java.util.Map;
import java.util.HashMap;
public class MapIterator extends WCMUsePojo{
Map<String, String> mapItems = new HashMap<String, String>();
@Override
    public void activate()throws Exception{
        mapItems.put("key1","value1");
        mapItems.put("key2","value2");
        mapItems.put("key3","value3");
        mapItems.put("key4","value4");
    }
    public Map<String,String> getMapItems(){
return mapItems;
    }
}

How to create JSON file in AEM/Adobe CQ5 Repository

Sample Java code Snippet

Resource metadataOptionJson = ResourceUtil.getOrCreateResource(
resolver,
parentPath+ "/sample.json",
Collections.singletonMap("jcr:primaryType",(Object) "nt:file"),
null, false);
Resource metadataOptionJsonJcrContent = ResourceUtil.getOrCreateResource(
resolver,
metadataOptionJson.getPath() + "/jcr:content",
Collections.singletonMap("jcr:primaryType",(Object) "nt:resource"),
null, false);

final ModifiableValueMap metadataOptionJsonProprties = metadataOptionJsonJcrContent.adaptTo(ModifiableValueMap.class);
if (metadataOptionJsonProprties.get("jcr:data") != null) {
// Remove the property first in case Types differ
metadataOptionJsonProprties.remove("jcr:data");
}

metadataOptionJsonProprties.put("jcr:mimeType", "application/json");
metadataOptionJsonProprties.put("jcr:encoding", "utf-8");
final ByteArrayInputStream bais = new ByteArrayInputStream(yourjsonString.getBytes(StandardCharsets.UTF_8));
metadataOptionJsonProprties.put("jcr:data", bais);
LOG.debug(String.format("%s : %s", "Options Json ", metadataOptionJson.getPath()));
resolver.commit();