Skip to main content
Solved

JSONTemplater fails on embedded HTML

  • September 3, 2025
  • 5 replies
  • 70 views

lifalin2016
Supporter
Forum|alt.badge.img+38

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": [{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": [{fme:process-features("ATTACHMENT")}]
,"attachmentStreams": []

}

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.

Best answer by ebygomm

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

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

alexbiz
Influencer
Forum|alt.badge.img+28
  • Influencer
  • September 3, 2025

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 ?


ebygomm
Influencer
Forum|alt.badge.img+45
  • Influencer
  • Best Answer
  • September 3, 2025

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


lifalin2016
Supporter
Forum|alt.badge.img+38
  • Author
  • Supporter
  • September 3, 2025

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.


ebygomm
Influencer
Forum|alt.badge.img+45
  • Influencer
  • September 3, 2025

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


takashi
Celebrity
  • September 3, 2025

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": [{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": [{fme:process-features("ATTACHMENT")}]
,"attachmentStreams": []

}