This is my first attempt at using Jinja or anything Python related, but our vendor has a new tool implemented that uses it, so here we are.
As a test, I'm using a free API as a data source and want to convert it through the tool's Jinja. API is http://www.floatrates.com/daily/usd.json...
{"eur":{
"code":"EUR",
"alphaCode":"EUR",
"numericCode":"978",
"name":"Euro",
"rate":0.90140326265491,
"date":"Tue, 21 Jan 2020 12:00:01 GMT",
"inverseRate":1.1093813850359},
"gbp":{
"code":"GBP",
"alphaCode":"GBP",
"numericCode":"826",
"name":"U.K. Pound Sterling",
"rate":0.76735727130961,
"date":"Tue, 21 Jan 2020 12:00:01 GMT",
"inverseRate":1.3031739417721},
"jpy":{
"code":"JPY",
"alphaCode":"JPY",
"numericCode":"392",
"name":"Japanese Yen",
"rate":109.99188913429,
"date":"Tue, 21 Jan 2020 12:00:01 GMT",
"inverseRate":0.009091579459819}...
My goal is to iterated through the content (which this tool has the response's body in the content property) and grab the code and eventual rate for each one. I know what to do once I can successfully get those values... Here is what I have so far
{% set Collection = a.content|to_json %}
{% for obj in Collection %}
{% set CurrentObject = obj %}
{{ Collection[CurrentObject].code }}
{% endfor %}
This doesn't appear to work however... if I do a.content|to_json['eur'].code then I get the EUR as a value, but I'm trying to not hardcode for each iteration.
Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…