Skip to main content
Question

Dynamically create attributes using two lists: one with labels and one with values


friesewoudloper
Forum|alt.badge.img

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?

 

5 replies

erik_jan
Contributor
Forum|alt.badge.img+18
  • Contributor
  • February 6, 2019

Hi Willy,

 

Have a look at this FME Hub transformer:

This one worked for me.

Erik Jan


friesewoudloper
Forum|alt.badge.img
erik_jan wrote:

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!


friesewoudloper
Forum|alt.badge.img

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.


erik_jan
Contributor
Forum|alt.badge.img+18
  • Contributor
  • February 6, 2019
erik_jan wrote:

Hi Willy,

 

Have a look at this FME Hub transformer:

This one worked for me.

Erik Jan

Made a small example workspace: listkeypair.fmw


takashi
Evangelist
  • February 7, 2019

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 {$labels[$i] : $vals[$i]}
|}

0684Q00000ArKElQAN.png


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings