Skip to main content

Hi all.

We’re migrating email submittals to a http based service, which takes a JSON body in a POST request.

One of the fields in the post body is “emailBody”, which can be text or html.

So I’m attempting to use a JSONTemplater to build this, but it fails:

JSONTemplater (XMLTemplaterFactory): All features received
JSONTemplater (XMLTemplaterFactory): The following error occurred near line 7, column 50 of the query:
JSONTemplater (XMLTemplaterFactory): invalid expression: syntax error, unexpected "QName", expecting "," or "}"
An error has occurred. Check the logfile above for details
Translation FAILED with 1 error(s) and 4 warning(s) (0 feature(s) output)

Line 7 in the ROOT expression is the HTML, with escaped apostrophes and removed linefeeds and whitespace between tags:

{
"emailFromId": "planinfo@lifa.dk", "emailFromName": "planinfo@lifa.dk"
,"emailAddresses": e{fme:process-features("TO")}]
,"emailCcToId": "","emailCcToName": ""
,"emailBccToId": "","emailBccToName": ""
,"emailSubject": "TEST planinfo 2025"
,"emailBody": " <html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>PlanInfo Service 2025-09-03</title><link href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css\" rel=\"stylesheet\"></head><body> ...... </body></html>"
,"zipAttachments": true
,"groupAttachments": true
,"groupedContentName": "ZippedAttachments"
,"attachments": m{fme:process-features("ATTACHMENT")}]
,"attachmentStreams": r]

}

The JSON is valid (without the “fme:process-feature()”), and JSONTemplater works just fine if I remove the value for “emailBody”.

I suspect the problem lies with the embedded use of “XMLTemplaterFactory” mentioned in the error messages, as it errs on the first escaped apostrophe.

I’ve tested it in 2025.1.1, and the problem remains.

Cheers.

Hey Lars, 

Could you share your workspace as a template, including the cached data?
Or maybe, could you share the entire HTML you’re trying to pass in the emailBody JSON key ?


I think if you use this syntax with double quotes in the JSON templater you should get the right outcome

"<html><head><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8""><title>PlanInfo Service 2025-09-03</title><link href=""https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"" rel=""stylesheet""></head><body> ...... </body></html>"

The output JSON will then have the \” escapes added


I think if you use this syntax with double quotes in the JSON templater you should get the right outcome

"<html><head><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8""><title>PlanInfo Service 2025-09-03</title><link href=""https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"" rel=""stylesheet""></head><body> ...... </body></html>"

The output JSON will then have the \” escapes added

Thanks ebygomm.

It seems to be correct, but I’ve looked at the help, and this rather un-JSON-like formatting isn’t mentioned anywhere ? Did you find this out by trial and error ?

I have worked with XMLTemplater, but not with JSONTemplater.


I’ve no idea how I discovered this originally, but it would have been when doing something in one of the XMLXquery transformers and the JSONTemplater is Xquery based I think


Hi ​@lifalin2016 ,

I think there is an issue in JSONTemplater. Hope someone from Safe will take a look into this.

Another workaround in the interim, I found that the JSONTempleter would work fine, If you store the HTML text into a feature attribute (e.g. called “_email_body”), and refer it in the template expression with the "fme:get-attribute" function, as in:

{
"emailFromId": "planinfo@lifa.dk", "emailFromName": "planinfo@lifa.dk"
,"emailAddresses": r{fme:process-features("TO")}]
,"emailCcToId": "","emailCcToName": ""
,"emailBccToId": "","emailBccToName": ""
,"emailSubject": "TEST planinfo 2025"
,"emailBody": fme:get-attribute("_email_body")
,"zipAttachments": true
,"groupAttachments": true
,"groupedContentName": "ZippedAttachments"
,"attachments": h{fme:process-features("ATTACHMENT")}]
,"attachmentStreams": t]

}

 


Reply