JKB
JKB

Reputation: 73

DBT: Convert string into list of dictionary which is passed as --vars

I am newbie to DBT and Jinja. I am trying to below variables as String and want to convert it to dictionary/json and iterate over it as a list

command to run:

dbt --debug run --models run_model --vars '{"filter_cols" : "{'A': 'val1','cond': 'AND'}"}'

Its gets passed as below to DBT:

['{"A":"val1","cond":"AND"}']

I expect it to be passed as below to DBT:

[{"A":"val1","cond":"AND"}]

Any sort of help and advice is much appreciated in advance.

Thanks

Upvotes: 2

Views: 3931

Answers (1)

Branden Ciranni
Branden Ciranni

Reputation: 492

Right now, you're running:

dbt --debug run --models run_model --vars '{"filter_cols" : "{'A': 'val1','cond': 'AND'}"}'

You wrap the inner dictionary in quotes, so it's getting passed in as a string. The --vars tag expects a YAML dictionary. Remove the quotes around your inner dictionary and it should work:

dbt --debug run --models run_model --vars '{"filter_cols" : {'A': 'val1','cond': 'AND'}}'

Upvotes: 1

Related Questions