Skip to main content
Solved

Can I populate the json templater automatically using attribute/values present in my source?

  • January 17, 2023
  • 2 replies
  • 258 views

geomax
Contributor
Forum|alt.badge.img+3

To populate in an automated way the json templater what I would to do is to add the string stored in 2 attributes that I created in the table of my source.

The first one is to create the list of attribute name and the second one to run the command in Json templater to add the value of the same attributes present in the source. ( see picture)

something like:

{

   "id":fme:get-attribute("id"),

   "@ns:com:here:customer:$(CustomerName)": {

 

                   "objectidOriginal": fme:get-attribute("objectidOriginal"),

                   "toaddr_l": fme:get-attribute("toaddr_l"),

                   "toaddr_r": fme:get-attribute("toaddr_r"),

                   ..............................

                   ..............................

                   ..............................

                   "filegdb_type": fme:get-attribute("filegdb_type")

}

 

I created this ROOT:

{

   "id":fme:get-attribute("id"),

   "@ns:com:here:customer:$(CustomerName)": 

 

                   [fme:process-features("ATTRIBUTENAME")]

 }

 

But I have problem to add the rigth sintax in the sub-template.

I tested something like that and others string:

 

{

   fme:get-attribute("attributename"):fme:get-attribute("CustomAttributes")

}

 

but doesn't work.

 

first of all, I am not sure if it is possible.

 

But if yes, do you have some suggestion?

 

Thanks

Max

Best answer by debbiatsafe

Hello @geomax​ 

One way to dynamically create JSON is to explode the attributes you want in the output JSON into features using the AttributeExploder, create text formatted as JSON in an AttributeCreator, and then insert the JSON object in the JSONTemplater using fme:get-json-attribute().

Alternatively, if you are familiar with XQuery, you can create a list of attribute names and values using an AttributeExploder and then use XQuery/JSONiq to insert them into the output JSON. This method uses less transformers but requires an understanding of XQuery.

I have attached an example workspace that demonstrates these two methods.

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

2 replies

debbiatsafe
Safer
Forum|alt.badge.img+20
  • Safer
  • Best Answer
  • January 19, 2023

Hello @geomax​ 

One way to dynamically create JSON is to explode the attributes you want in the output JSON into features using the AttributeExploder, create text formatted as JSON in an AttributeCreator, and then insert the JSON object in the JSONTemplater using fme:get-json-attribute().

Alternatively, if you are familiar with XQuery, you can create a list of attribute names and values using an AttributeExploder and then use XQuery/JSONiq to insert them into the output JSON. This method uses less transformers but requires an understanding of XQuery.

I have attached an example workspace that demonstrates these two methods.


geomax
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • January 23, 2023

Hello @debbiatsafe​ ,

thanks for you answer and workbench. I will test your model and I let you know.

About Xquery, I am not familiar. I use the documentation present on the Help of the transformer.

Max


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