Solved

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

  • 17 January 2023
  • 2 replies
  • 46 views

Badge +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

icon

Best answer by debbiatsafe 19 January 2023, 01:29

View original

2 replies

Userlevel 3
Badge +17

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.

Badge +3

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

Reply