Skip to content

Instantly share code, notes, and snippets.

@srkiNZ84
Last active February 10, 2020 02:46
Show Gist options
  • Save srkiNZ84/5e585551bfd32c70e3e544a83a1b1b25 to your computer and use it in GitHub Desktop.
Save srkiNZ84/5e585551bfd32c70e3e544a83a1b1b25 to your computer and use it in GitHub Desktop.
Groovy test to check whether it does or does not interpert hash values
foo:
bar:
baz: something
anotherfoo:
secondbar: otherthing
@Grab('org.yaml:snakeyaml')
import org.yaml.snakeyaml.Yaml
Yaml parser = new Yaml()
def example = parser.load(("/tmp/foobar.yaml" as File).text)
println(example)
def varKeyBaz = "baz"
def varKeyBarBaz = 'bar.baz'
println("Var key is ${varKeyBaz}")
println(example.foo.bar."${varKeyBaz}") // works
println(example.foo."${varKeyBarBaz}") // does not work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment