Skip to content

Instantly share code, notes, and snippets.

@ivanarrizabalaga
Created October 9, 2013 11:44
Show Gist options
  • Save ivanarrizabalaga/6899973 to your computer and use it in GitHub Desktop.
Save ivanarrizabalaga/6899973 to your computer and use it in GitHub Desktop.
Groovy: Dynamic access to nested properties via GString
Map data=[
one:[
two:"2222",
three:"333"
]
]
String nestedExpression="one.two"
String output=nestedExpression.tokenize('.').inject(data) {v, k -> v."$k"}
println output // "2222"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment