Maybe someone else can confirm, but I suspect that the ampersand is considered a special character in XQuery, cf. https://en.wikibooks.org/wiki/XQuery/Special_Characters
Try using a StringReplacer to replace the ampersands with either "&" or to "&".
Yes, in XQuery expressions, the ampersand can only be represented using the entity reference or character reference. See also this link.
W3C Recommendation | XQuery 3.0: An XML Query Language | 2.4.5 URI Literals
This expression causes the error.
{
"CABINET PIERRE SMITH & ASSOCIES": "foo bar"
}
To avoid the error,
a) escape the ampersand with the predefined entity reference (&),
{
"CABINET PIERRE SMITH & ASSOCIES": "foo bar"
}
b) or save the string literal as a feature attribute (e.g. called "name") beforehand and use FME predefined XQuery function "fme:get-attribute" to put the value in the expression.
{
fme:get-attribute("name"): "foo bar"
}
Note: Since the function escapes the ampersand internally when the expression is evaluated, you don't need to replace the ampersand within the "name" attribute value with the entity reference.
Yes, in XQuery expressions, the ampersand can only be represented using the entity reference or character reference. See also this link.
W3C Recommendation | XQuery 3.0: An XML Query Language | 2.4.5 URI Literals
This expression causes the error.
{
"CABINET PIERRE SMITH & ASSOCIES": "foo bar"
}
To avoid the error,
a) escape the ampersand with the predefined entity reference (&),
{
"CABINET PIERRE SMITH & ASSOCIES": "foo bar"
}
b) or save the string literal as a feature attribute (e.g. called "name") beforehand and use FME predefined XQuery function "fme:get-attribute" to put the value in the expression.
{
fme:get-attribute("name"): "foo bar"
}
Note: Since the function escapes the ampersand internally when the expression is evaluated, you don't need to replace the ampersand within the "name" attribute value with the entity reference.
Ok ! Thanks for the answer ! If I use "&" do I need to replace it back when loading it (I will use a python caller, load the json in a python dictionnary, then write it in mongodb) ?
What's bother me though, is that I indeed used fme:get-attribute to create the json structure in a previous JSON Templater, then used the resulting json attribute in the second JSON Templater as a sub-template... (I guess that's why the & is no-longer escaped, the nested json might be passed as a raw string somewhere inbetween) maybe if I define all the nested sub-templates in the same json templater, the & would be correctly escaped... I will try that.
Ok ! Thanks for the answer ! If I use "&" do I need to replace it back when loading it (I will use a python caller, load the json in a python dictionnary, then write it in mongodb) ?
What's bother me though, is that I indeed used fme:get-attribute to create the json structure in a previous JSON Templater, then used the resulting json attribute in the second JSON Templater as a sub-template... (I guess that's why the & is no-longer escaped, the nested json might be passed as a raw string somewhere inbetween) maybe if I define all the nested sub-templates in the same json templater, the & would be correctly escaped... I will try that.
I don't think the error could occur even if you are using multiple JSONTemplaters in a series, unless an ampersand exists within a string literal in a template expression. Can you post a workspace example which illustrates your problem?
I don't think the error could occur even if you are using multiple JSONTemplaters in a series, unless an ampersand exists within a string literal in a template expression. Can you post a workspace example which illustrates your problem?
Yes ! I will try to create a specific workspace to showcase this