title: Freemarker - Iterate through nested maps and nested lists
body: <p>I have to iterate through a <code>List&lt;Map&lt;String, List&lt;Map&lt;String, String&gt;&gt;&gt;&gt;</code> and print all its content.</p>
  
  <p>My problem is that each time I use map's bracket syntax (<a href="http://freemarker.org/docs/ref_builtins_hash.html" rel="nofollow">like in the documentation</a>) at nested levels I have a syntax issue. Could you show me how to handle nested levels for a type like <code>List&lt;Map&lt;String, List&lt;Map&lt;String, String&gt;&gt;&gt;&gt;</code> ?</p>
  
  <p>I have tested this:</p>
  
  <pre><code>&lt;!-- List&lt;Map&lt;String, List&lt;Map&lt;String, String&gt;&gt;&gt;&gt; --&gt;
  &lt;#list myList as map1&gt;
  
      &lt;!-- Map&lt;String, List&lt;Map&lt;String, String&gt;&gt;&gt; --&gt;
      &lt;#list map1?keys as key1&gt;
          My Key: ${key1}
  
          &lt;!-- List&lt;Map&lt;String, String&gt;&gt; --&gt;
          &lt;#list map1[key1] as map2&gt;
  
  
              &lt;!-- Map&lt;String, String&gt; --&gt;
              &lt;#list map2?keys as key2&gt;
                  My Key: ${key2} | My Value: ${map2[key2]}
              &lt;/#list&gt;
          &lt;/#list&gt;
      &lt;/#list&gt;
  &lt;/#list&gt;
  </code></pre>
  
  <p>And I have this error:</p>
  
  <pre><code>java.lang.RuntimeException: freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
  ==&gt; map1[key1]  [in template "hello.html" at line 39, column 32]
  
  ----
  Tip: It's the final [] step that caused this error, not those before it.
  ----
  Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use &lt;#if myOptionalVar??&gt;when-present&lt;#else&gt;when-missing&lt;/#if&gt;. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
  ----
  
  ----
  FTL stack trace ("~" means nesting-related):
      - Failed at: #list map1[key1] as map2  [in template "hello.html" at line 39, column 25]
  ----
  </code></pre>
  
  <p>I am using Freemarker <a href="http://mvnrepository.com/artifact/org.freemarker/freemarker/2.3.23" rel="nofollow">2.3.23</a>. Thanks.</p>