Solved

JSONTemplater failse on ampersant

  • 10 March 2021
  • 5 replies
  • 3 views

Badge

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?

icon

Best answer by david_r 11 March 2021, 08:46

View original

5 replies

Userlevel 4

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" } ] } ] }

 

Badge

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

Userlevel 4

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

Badge

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

Badge +2

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

Reply