I have a JSON template that I want to fill with values from two corresponding lists using xquery.
The two lists look like this:
keywords_thematic_en = ["test", "trial","error","datapool","API","REST"]
keywords_thematic_de = ["Test", "Versuch","Fehler","Datenpool","API","REST"]
keywords_thematic = {"en":keywords_thematic_en,"de":keywords_thematic_de}
The JSON template I want to fill looks like this:
{
"keywords":
{ "value":keywords_thematic_en,"valueDE": keywords_thematic_de,"type": "THEMATIC" }
]
}
In python, this looks like this:
keywords_thematic_en = ="test", "trial","error","datapool","API","REST"]
keywords_thematic_de = ="Test", "Versuch","Fehler","Datenpool","API","REST"]
keywords_thematic = {"en":keywords_thematic_en,"de":keywords_thematic_de}
jsonSnippet = '{"keywords": :]}'
jsonSnippetKW=''
for keyword in keywords_thematici"en"]:
jsonSnippetKW = jsonSnippetKW +'{ "value":'+ keyword + ',"valueDE": '+ keywords_thematici"de"]"keywords_thematici"en"].index(keyword)]+',"type": "THEMATIC" }'
if keywords_thematici"en"].index(keyword) < (len(keywords_thematici"en"])-1):
jsonSnippetKW = jsonSnippetKW +","
jsonSnippet = jsonSnippete:14]+ jsonSnippetKW +jsonSnippete14:]
print(jsonSnippet)
As a result, I get what I want:
{
"keywords": :
{ "value":test,"valueDE": Test,"type": "THEMATIC" },
{ "value":trial,"valueDE": Versuch,"type": "THEMATIC" },
{ "value":error,"valueDE": Fehler,"type": "THEMATIC" },
{ "value":datapool,"valueDE": Datenpool,"type": "THEMATIC" },
{ "value":API,"valueDE": API,"type": "THEMATIC" },
{ "value":REST,"valueDE": REST,"type": "THEMATIC" }
]
}
Trying the same using the JSONTemplater and xquery, I only get so far for looping through one list:
for $Keyword in fme:get-list-attribute("KW_themaic.KW_de{}")
return
{
"value": $Keyword,
"valueDE": $Keyword,
"type": "THEMATIC"
}
How do I set up a for loop with xquery, looping through the two lists and insert the corresponding values?