I am new to ruby. I have an existing JSON file in the below format.
{
"ASRtest": {
"ASRHDR": "This is asr HDR",
"ASRTestType": "DevTest",
"Scenario": [
{
"ScenarioNumber": 1,
"ScenarioName": "HTTP Validation",
"ScenarioDescription": "Validate if the API alows access over HTTP",
"ScExecutionStatus": "Execution Complete",
"ScenarioStatus": "In-Complete",
"ScenarioSeverity": false,
"TestCase": [
{
"TestCaseNumber": 1,
"TestCaseName": "HTTP Validation - using POST method ",
"TcExecutionStatus": "Execution Error",
"TcStatus": "NA",
"TcSeverity": "NA"
}
]
}
]
}
}
I am reading this file in my ruby program and want to another scenario to this file Like
{
"ASRtest": {
"ASRHDR": "This is asr HDR",
"ASRTestType": "DevTest",
"Scenario": [
{
"ScenarioNumber": 1,
"ScenarioName": "HTTP Validation",
"ScenarioDescription": "Validate if the API alows access over HTTP",
"ScExecutionStatus": "Execution Complete",
"ScenarioStatus": "In-Complete",
"ScenarioSeverity": false,
"TestCase": [
{
"TestCaseNumber": 1,
"TestCaseName": "HTTP Validation - using POST method ",
"TcExecutionStatus": "Execution Error",
"TcStatus": "NA",
"TcSeverity": "NA"
}
]
},
{
"ScenarioNumber": 2,
"ScenarioName": "SC2",
"ScenarioDescription": "Desc",
"ScExecutionStatus": "Execution Complete",
"ScenarioStatus": "In-Complete",
"ScenarioSeverity": false,
"TestCase": [
{
"TestCaseNumber": 1,
"TestCaseName": "Some Name ",
"TcExecutionStatus": "Execution Error",
"TcStatus": "NA",
"TcSeverity": "NA"
}
]
}
]
}
}
I have read the file using the below code
@template_file = JSON.parse(File.read('SummaryTemplate.json'))
@ASR_Test = @template_file['ASRtest']
@ASR_Test
@scenario = @ASR_Test['Scenario']
when I try the below code
@scenario[1]['ScenarioNumber'] = 2
it gives me an error undefined method `[]=' for nil:NilClass (NoMethodError) the variable @scenario only has 1 occurrence and it does not allow me to add a second occurrence.
Could someone please help me with this issue.