Skip to main content

Hello all,

 

I'm trying to get a json templater setup so that I can use an API to ingest some data.

 

The challenge is syntax related, but perhaps I'm not organizing things quite correctly.

 

I have some nested structure, and I've attempted to use sub templates for those parts. I've got body of those three expressions in the three attached text files matching the sections.

 

error message is:

 

2023-02-22 13:28:33|  0.1| 0.0|WARN |JSONTemplater (XMLTemplaterFactory): The following error occurred near line 29, column 17 of the query:

2023-02-22 13:28:33|  0.1| 0.0|WARN |JSONTemplater (XMLTemplaterFactory): invalid expression: syntax error, unexpected ExprSingle (missing comma "," between expressions?)

2023-02-22 13:28:33|  0.1| 0.0|ERROR |JSONTemplater (XMLTemplaterFactory): An error occurred while parsing the ROOT template

2023-02-22 13:28:33|  0.1| 0.0|ERROR |JSONTemplater (XMLTemplaterFactory): An error has occurred. Check the logfile above for details

 

 

Hi @jeffreymc​,

In the root template, it seems that there will be multiple cost allocations for each LineItem, judging by the '9]' placements. Would you mind sharing an example of the JSON you want to get out of the templater?


You are correct that multiple cost allocations for each LineItem are expected.

 

Perhaps I could ask a follow up question regarding my root example?

 

Should the object above "DATA" be consider the root and DATA, LINEITEMS, AND ALLOCATIONS all be sub templater? or does the way it's currently broken out seem acceptable?

 

Thanks for attempting to help me, I'm sorry I'm struggling to generate everything required for appropriate help.

 

 


Hi @jeffreymc​,

In the root template, it seems that there will be multiple cost allocations for each LineItem, judging by the '9]' placements. Would you mind sharing an example of the JSON you want to get out of the templater?

Sorry for the whining, that was easier than I thought. Here is an example output, apologies if I abused the syntax too much.


You are correct that multiple cost allocations for each LineItem are expected.

 

Perhaps I could ask a follow up question regarding my root example?

 

Should the object above "DATA" be consider the root and DATA, LINEITEMS, AND ALLOCATIONS all be sub templater? or does the way it's currently broken out seem acceptable?

 

Thanks for attempting to help me, I'm sorry I'm struggling to generate everything required for appropriate help.

 

 

It's hard to have a multilevel nesting in a single JSONTemplater due to only having one level of Group By, so I would recommend using two JSONTemplaters:

  • first templater creates LineItem records, so LineItem JSON would be Root and Cost Allocations would be the subs.
  • second templater creates full record, so Root info would go to Root and JSON from first templater goes to sub. Use fme:get-json-attribute("_lineitem_json") instead of fme:get-attribute("_lineitem_json") since lineitem is already JSON formatted.

It's hard to have a multilevel nesting in a single JSONTemplater due to only having one level of Group By, so I would recommend using two JSONTemplaters:

  • first templater creates LineItem records, so LineItem JSON would be Root and Cost Allocations would be the subs.
  • second templater creates full record, so Root info would go to Root and JSON from first templater goes to sub. Use fme:get-json-attribute("_lineitem_json") instead of fme:get-attribute("_lineitem_json") since lineitem is already JSON formatted.

Thanks a ton Dave! That tip got us there. It was a matter of using two templaters, one set to process-template, second one set to process-features, and then giving each one an appropriate attribute to group on. 😎


Reply