Skip to main content
Solved

JSON Templater Syntax error, expecting a "," need some advice

  • February 22, 2023
  • 5 replies
  • 64 views

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

 

 

Best answer by daveatsafe

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.
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • 1637 replies
  • February 22, 2023

Hi @jeffreymc​,

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


  • Author
  • 6 replies
  • February 23, 2023

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.

 

 


  • Author
  • 6 replies
  • February 23, 2023

Hi @jeffreymc​,

In the root template, it seems that there will be multiple cost allocations for each LineItem, judging by the '[]' 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.


daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • 1637 replies
  • Best Answer
  • February 23, 2023

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.

  • Author
  • 6 replies
  • February 24, 2023

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. 😎