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 ()
}
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.
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
If I understand your requirement correctly, this workspace example would be a possible way.
dynamic-jsontemplater.fmwt (FME 2019.0.0.1)
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 👍