Skip to main content
Solved

JSONTemplater failse on ampersant

  • March 10, 2021
  • 5 replies
  • 28 views

michielschram
Contributor
Forum|alt.badge.img+6

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

 

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

david_r
Celebrity
  • 8392 replies
  • 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
Contributor
Forum|alt.badge.img+6
  • Author
  • Contributor
  • 16 replies
  • March 12, 2021

@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
  • 8392 replies
  • March 12, 2021

@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
Contributor
Forum|alt.badge.img+6
  • Author
  • Contributor
  • 16 replies
  • March 12, 2021

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


chrisatsafe
Contributor
Forum|alt.badge.img+2
  • Contributor
  • 606 replies
  • March 16, 2021

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