Parse the JSON file in Ruby script and obtain value for "key"
My JSON file looks like
"terraform": [
{
"backend": [
{
"s3": [
{
"bucket": "terraform-dev",
"dynamodb": "terraform_files",
"encrypt": "true",
"key": "Apple/Employee/Background/terraform.tfstate"
}
]
}
],
"required_version": "~> 0.11.8"
}
]
I tried writing this script in Ruby
#!/usr/bin/env ruby
require "json"
file = File.open "/Users/Test/conf.json"
data = JSON.load file
mykey= data['terraform'].first['backend']['s3']['key']
print mykey
file.close
Expected result: Apple/Employee/Background/terraform.tfstate
Error Message: no implicit conversion of String into Integer (TypeError)