Complex variables and a key with a hyphen

Hello Everyone,

I’m trying to reference a complex variable, but one of the words has a hyphen which breaks things.

Is there a way to set a fact the “specificVar” value from the last line in 1 set_fact statement?
So right now I’ve split up the setting the vars into two different set_fact statements

set_fact:
intermediate_var: “{{ example_text[‘json’][‘output-parameters’] }}”
set_fact:
machine_var: “{{ intermediate_var[0].value.string.value }}”

“json”: {
“current-item-for-display”: “item0”,
“name”: “Get-Stuff”,
“output-parameters”: [
{
“name”: “machineName”,
“scope”: “local”,
“type”: “string”,
“value”: {
“string”: {
“value”: “specificVar”

}

Many Thanks,

Hello Everyone,

I'm trying to reference a complex variable, but one of the words has a
hyphen which breaks things.

Breaks what? With notation hyphen is allowed.

Is there a way to set a fact the "specificVar" value from the last line in
1 set_fact statement?
So right now I've split up the setting the vars into two different set_fact
statements

set_fact:
     intermediate_var: "{{ example_text['json']['output-parameters'] }}"
set_fact:
     machine_var: "{{ intermediate_var[0].value.string.value }}"

Do what you have done

{{ example_text['json']['output-parameters'][0].value.string.value }}

I was trying to use all square brackets instead of mixing dot notation and brackets.
Thanks for the quick answer Kia, works great.

That would be

{{ example_text['json']['output-parameters'][0]['value']['string']['value'] }}