Skip to main content
Solved

List Attributes in JsonTemplater

  • June 15, 2018
  • 6 replies
  • 78 views

danilo_fme
Celebrity
Forum|alt.badge.img+52

Hi,

 

I'm working with the transformer JsonTemplater to create a json file. The source is a list of attributes, for example:

_list{0}.Date

_list{1}.Date

_list{0}.Age

_list{1}.Age

 

My Workspace translate with successful with just list of attribute:
{
    
   
    "Attributes" : [
        for $value in fme:get-list-attribute(("_list{}.Date")
            return {"Date" : $value}]
 
}

My question: How can I configure to receive more than list of attribute, in this case _list{}.Age ?

 

 

Thanks

Best answer by jdh

This may not be the most elegant solution, but should work.

 

{
"Attributes":[  for $Age at $pos in fme:get-list-attribute("_list{}.Age")
     let $Date := fme:get-attribute(concat("_list{",$pos - 1,"}.Date"))
     return {"Date":$Date, "Age": $Age}]
}
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

6 replies

jdh
Contributor
Forum|alt.badge.img+40
  • Contributor
  • Best Answer
  • June 15, 2018

This may not be the most elegant solution, but should work.

 

{
"Attributes":[  for $Age at $pos in fme:get-list-attribute("_list{}.Age")
     let $Date := fme:get-attribute(concat("_list{",$pos - 1,"}.Date"))
     return {"Date":$Date, "Age": $Age}]
}

danilo_fme
Celebrity
Forum|alt.badge.img+52
  • Author
  • Celebrity
  • June 15, 2018

This may not be the most elegant solution, but should work.

 

{
"Attributes":[  for $Age at $pos in fme:get-list-attribute("_list{}.Age")
     let $Date := fme:get-attribute(concat("_list{",$pos - 1,"}.Date"))
     return {"Date":$Date, "Age": $Age}]
}
Hi @jdh

 

 

 

Is works now, thank you!

 

 

Danilo

 


takashi
Celebrity
  • June 17, 2018

This may not be the most elegant solution, but should work.

 

{
"Attributes":[  for $Age at $pos in fme:get-list-attribute("_list{}.Age")
     let $Date := fme:get-attribute(concat("_list{",$pos - 1,"}.Date"))
     return {"Date":$Date, "Age": $Age}]
}
This expression is also available.

 

{
    "Attrbutes" : [
        let $dates := fme:get-list-attribute("_list{}.Date")
        for $age at $p in fme:get-list-attribute("_list{}.Age")
        return { "Date" : $dates[$p], "Age" : $age }
    ]
}

danilo_fme
Celebrity
Forum|alt.badge.img+52
  • Author
  • Celebrity
  • June 18, 2018
This expression is also available.

 

{
    "Attrbutes" : [
        let $dates := fme:get-list-attribute("_list{}.Date")
        for $age at $p in fme:get-list-attribute("_list{}.Age")
        return { "Date" : $dates[$p], "Age" : $age }
    ]
}
Excellent @takashi

 

 , thank you!

johnglick
Contributor
Forum|alt.badge.img+7
  • Contributor
  • August 30, 2019

This may not be the most elegant solution, but should work.

 

{
"Attributes":[  for $Age at $pos in fme:get-list-attribute("_list{}.Age")
     let $Date := fme:get-attribute(concat("_list{",$pos - 1,"}.Date"))
     return {"Date":$Date, "Age": $Age}]
}

@takashi how would I make your expression work with 3 list attributes?  


takashi
Celebrity
  • August 30, 2019

@takashi how would I make your expression work with 3 list attributes?  

example:

{
    "Attributes" : [
        let $a := fme:get-list-attribute("_list{}.a")
        let $b := fme:get-list-attribute("_list{}.b")
        for $c at $i in fme:get-list-attribute("_list{}.c")
        return
        {
            "A" : $a[$i],
            "B" : $b[$i],
            "C" : $c
        }
    ]
}