Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Added on November 30, 2022 7:04PM
Likes: 0
Replies: 2
Hi,
I would like to call variables in nested dictionary/json.
Nested Global vars:
{
"set1": {
"input_file": "test/input.xlsx",
"output_fle": "test/output.xlsx",
},
"set2": {
"input_file": "test/input.xlsx",
"output_fle": "test/output.xlsx",
}
}
In Recipe: I don't think this is the right way to call variables in nested json.
input_file = dataiku.get_custom_variables()["set1"]["input_file"]
print(input_file)
Could anyone please help me with this?
Thanks!
Srini
Hi @Srini_E
,
First, I had to remove some extra ',' (commas) when setting the variables, as in version 11.0.3 it complained when there was a comma at the end of the last element withing a {} group.
Second, you are right, one you get the variable with:
dataiku.get_custom_variables()['set1']
What is returned is not a dictionary, but a string.
I found a workaround
import ast ast.literal_eval(dataiku.get_custom_variables()['set1'])['input_file']
This will transform the string into a dict, and you can extract the subvariables. In this case I've got 'test/input.xlsx'
Is not the cleanest solution, but it is a valid workaround. Maybe this should be requested as a new feature?
Hope this helps
Thanks for the work-around solution @Ignacio_Toledo
. Yes, this should be requested as a new feature.
Thanks!
Srini