title: Groovy: isn't there a stringToMap out of the box?
body: <p>as a tcl developer starting with groovy, I am a little bit surprised about the list and map support in groovy. Maybe I am missing something here.</p>
  
  <p>I am used to convert between strings, lists and arrays/maps in tcl on the fly. In tcl, something like</p>
  
  <pre><code>"['a':2,'b':4]".each {key, value -&gt; println key + " " + value}
  </code></pre>
  
  <p>would be possible, where as in groovy, the each command steps through each character of the string.</p>
  
  <p>This would be much of a problem is I could easily use something like the split or tokenize command, but because a serialized list or map isn't just "a:2,b:4", it is a little bit harder to parse.</p>
  
  <p>It seems that griffon developers use a stringToMap library (<a href="http://code.google.com/p/stringtomap/" rel="noreferrer">http://code.google.com/p/stringtomap/</a>) but the example can't cope with the serialized maps either.</p>
  
  <p>So my question is now: what's the best way to parse a map or a list in groovy?</p>
  
  <p>Cheers,
  Ralf</p>
  
  <p>PS: it's a groovy question, but I've tagged it with grails, because I need this functionality for grails where I would like to pass maps through the URL</p>
  
  <p><strong>Update:</strong> This is still an open question for me... so here are some updates for those who have the same problem:</p>
  
  <ul>
  <li>when you turn a Map into a String, a <code>.toString()</code> will result in something which can't be turned back into a map in all cases, but an <code>.inspect()</code> will give you a String which can be evaluated back to a map!</li>
  <li>in Grails, there is a <code>.encodeAsJSON()</code> and <code>JSON.parse(String)</code> - both work great, but I haven't checked out yet what the parser will do with JSON functions (possible security problem)</li>
  </ul>