Skip to main content

Hi,

For each feature in my dataset, I have two lists: one containing labels and one containing values.

label{0}: ID
label{1}: Name
label{2}: Type
label{3}: Country

val{0}: 1
val{1}: Groningen
val{2}: Place
val{3}: The Netherlands

There may be more or less items in both lists. The contents of `label` may be completely different. But `label` and `val` always have an equal number of items.

How can I dynamically create attributes from these lists, with the contents of `label` as attribute names and `val` as attribute values?

 

Hi Willy,

 

Have a look at this FME Hub transformer:

This one worked for me.

Erik Jan


Hi Willy,

 

Have a look at this FME Hub transformer:

This one worked for me.

Erik Jan

Thank you @erik_jan. That looks like a good solution!


Update:

I added a PythonCaller with code based upon this example by @takashi

http://fme-memorandum-takashi.blogspot.com/2013/09/extract-list-attribute-elements-in.html

This does the job.

I'm also going to take a look at the solution @erik_jan provided. I 'd prefer a solution without Python code.


Hi Willy,

 

Have a look at this FME Hub transformer:

This one worked for me.

Erik Jan

Made a small example workspace: listkeypair.fmw


The ListKeyValuePairExtractor is a good solution.

Interestingly, JSON operations can do that too. FYI.

JSON Template Expression:

{|
    let $labels := fme:get-list-attribute('label{}')
    let $vals := fme:get-list-attribute('val{}')
    for $i in (1 to count($labels))
    return {$labelsn$i] : $vals<$i]}
|}

0684Q00000ArKElQAN.png


Reply