Skip to main content
Solved

JSONTemplater failse on ampersant


michielschram
Forum|alt.badge.img

When creating more complex JSON's with a double JSONTemplater the workspace fails on ampersants (&).

 

Sweco_CreateComplexJSON-AmpersantError_20210310With just one JSONTemplater the templater can handle &-characters. Of course I can do a work around bij replacing but that's not what I want. Has anyone an idea how to fix this?

Best answer by david_r

You shouldn't use @Value() functions in the JSONTemplater (or XMLTemplater, for that matter), you need to use XQuery functions only.

If you change the second JSONTemplater as follows, it works:

[fme:get-json-attribute("_result")]

Notice that we have to use a specific function for blocks that already contain valid JSON, so that it's not interpreted as a string.

Result:

{ "report" : [ { "company" : "Safe Software", "founderslist" : [ { "founders" : "Don & Dale" } ] } ] }

 

View original
Did this help you find an answer to your question?

5 replies

david_r
Celebrity
  • Best Answer
  • March 11, 2021

You shouldn't use @Value() functions in the JSONTemplater (or XMLTemplater, for that matter), you need to use XQuery functions only.

If you change the second JSONTemplater as follows, it works:

[fme:get-json-attribute("_result")]

Notice that we have to use a specific function for blocks that already contain valid JSON, so that it's not interpreted as a string.

Result:

{ "report" : [ { "company" : "Safe Software", "founderslist" : [ { "founders" : "Don & Dale" } ] } ] }

 


michielschram
Forum|alt.badge.img

@david_r​ thank you for your response. Actually you solution can be found in the JSONTemplater help:

In the JSONTemplater, the fme:get-attribute, fme:get-list-attribute and fme:get-json-attribute functions are particularly useful. Only functions which do not alter the feature are permitted. See the XQuery Functions documentation for more information on the available functions.

We might ask @safesoftware safesoftware​ to add an extra example on adding JSON to a JSON so it's more obvious.


david_r
Celebrity
  • March 12, 2021
michielschram wrote:

@david_r​ thank you for your response. Actually you solution can be found in the JSONTemplater help:

In the JSONTemplater, the fme:get-attribute, fme:get-list-attribute and fme:get-json-attribute functions are particularly useful. Only functions which do not alter the feature are permitted. See the XQuery Functions documentation for more information on the available functions.

We might ask @safesoftware safesoftware​ to add an extra example on adding JSON to a JSON so it's more obvious.

Indeed, most of the replies I'm posting here are things that are already available in the documentation :-) But sometimes it is buried deep into a section that must be manually expanded first, or you really have to know what to look for, so it's not always obvious finding the relevant part.


michielschram
Forum|alt.badge.img

Thank you for being part of the community! You're valuable, you're valued.


chrisatsafe
Contributor
Forum|alt.badge.img+2
  • Contributor
  • March 16, 2021
michielschram wrote:

@david_r​ thank you for your response. Actually you solution can be found in the JSONTemplater help:

In the JSONTemplater, the fme:get-attribute, fme:get-list-attribute and fme:get-json-attribute functions are particularly useful. Only functions which do not alter the feature are permitted. See the XQuery Functions documentation for more information on the available functions.

We might ask @safesoftware safesoftware​ to add an extra example on adding JSON to a JSON so it's more obvious.

Hi @michielschram​ ,

I think that's a great idea. I'm sure the team could add an Examples section to the JSONTemplater doc like we have in other transformers, like the AttributeManager. With regards sections needing to be manually expanded, one thing that might be helpful to keep in mind is the expand all sections button at the top right of page. Once clicked, using the search function (CTRL+F) will perform the search on the expanded sections as well. Just a useful tip in case you are searching the page on keywords as that might help you find what you're looking for

 

2021-03-16_10-24-53I've filed a request to include an examples section on the JSONTemplater doc (ref: TECHPUBS-7100). Let me know if you have any other questions/concerns.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings