Skip to main content
Question

JSON Templater - how to export attributes with value?


lazarlubomir
Contributor
Forum|alt.badge.img+7

Hello everybody,

please, Im trying to automate creation of JSON and I need to get exported JSONs only with attributes, which are exposed and have values (not null etc.). Please, does anybody know how to solve this problem via JSON Templater?

Thank You so much!

Lubo

5 replies

jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • May 7, 2019

If I understand correctly,  you know the attributes you want to include in the json, but you only want to insert them if there is a value.

 

 

Using the JSONTemplater, you can use an xquery conditional statement
{
 if (fme:has-attribute("A"))
 then {"A": fme:get-attribute("A")}
 else ()
} 

david_r
Celebrity
  • May 8, 2019

You can also try using the JSONFormatter after the JSONTemplater:

If you have a lot of attributes in your JSONTemplater it may be a bit less work than creating an if-statement for each of them, although I suspect it's somewhat faster in execution.


lazarlubomir
Contributor
Forum|alt.badge.img+7
  • Author
  • Contributor
  • May 8, 2019

Hello @jdh , @david_r,

thank both of you! Probably, I should describe deeply my issue - As source data, I have many feature types with different spectrum of attributes. And I wanna convert data of them to JSON file as easy as possible. So I dont wanna define special template in JSON templater for every feature type, but I need one general definition - you can imagine that as dynamic mode of attributes writing on writer.

Is there any way how to reach that? Your supposed way could be used, but it means for me to prepare template in JSON templater, where I should write all names of attributes.

Thank You so much!

Lubo

 


takashi
Influencer
  • May 8, 2019

If I understand your requirement correctly, this workspace example would be a possible way.

dynamic-jsontemplater.fmwt (FME 2019.0.0.1)


outlook
Contributor
Forum|alt.badge.img+3
  • Contributor
  • June 15, 2022
takashi wrote:

If I understand your requirement correctly, this workspace example would be a possible way.

dynamic-jsontemplater.fmwt (FME 2019.0.0.1)

@Takashi Iijima​ excellent solution 👍


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