Skip to main content
Solved

How to create key:value pair in JSON from fme_attrib_info{}.field_name and fme_attrib_info{}.field_value?

  • August 14, 2020
  • 1 reply
  • 57 views

jspratt
Participant
Forum|alt.badge.img

I have attempted a few different techniques to get my desired output.

1.) Reader->AttributeExposer->JSONTemplater

2.) Reader->AttributeExposer->ListConcatenator->JSONTemplater

3.) Reader->AttributeExposer->JSON Writer

4.) Reader->AttributeExposer->ListKeyValuePairExtractor->

5.) Reader->AttributeExposer->ListExploder->JSONTemplater

6.) Others

I am working with values such as:

objid | fme_attrib_info{}.field_name | fme_attrib_info{}.field_value |
-------+--------------------------------------+--------------------------------------|
1       | SERIAL_NUM                       |          12345                          |
2       | TYPE                                     |          SOME_TYPE              | 

 

My desired output would be as follows:

{
    "SERIAL_NUM""123456",
    "TYPE""SOMETYPE
}

I've used the tutorial on site here for extracting attributes from CAD blocks. Now, I would like to take these attributes and make a json payload per unique block to be written to a database. How might I go about doing something like that?

Thanks!

Best answer by takashi

Hi @jspratt​ , a possible way is to use the ListExploder and the JSONTemplater with a sub expression.

Root expression:

{fme:process-features("SUB") |}

SUB expression:

{fme:get-attribute("field_name") : fme:get-attribute("field_value")}

 

listexploder_jsontemplater

 

 

Alternatively you can get the same result using just a single JSONTemplater with this Root expression. In this case, you don't need to use the ListExploder.

{|
    let $values := fme:get-list-attribute('fme_attrib_info{}.field_value')
    for $name at $i in fme:get-list-attribute('fme_attrib_info{}.field_name')
    return {$name : $values[$i]}
|}

 

View original
Did this help you find an answer to your question?

1 reply

takashi
Influencer
  • Best Answer
  • August 15, 2020

Hi @jspratt​ , a possible way is to use the ListExploder and the JSONTemplater with a sub expression.

Root expression:

{fme:process-features("SUB") |}

SUB expression:

{fme:get-attribute("field_name") : fme:get-attribute("field_value")}

 

listexploder_jsontemplater

 

 

Alternatively you can get the same result using just a single JSONTemplater with this Root expression. In this case, you don't need to use the ListExploder.

{|
    let $values := fme:get-list-attribute('fme_attrib_info{}.field_value')
    for $name at $i in fme:get-list-attribute('fme_attrib_info{}.field_name')
    return {$name : $values[$i]}
|}

 


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