Skip to main content
Solved

How to handle a booleans in the JSONTemplater

  • March 10, 2021
  • 3 replies
  • 185 views

michielschram
Contributor
Forum|alt.badge.img+6

When using the JSONTemplater I want to be able to add a real boolean to the template and not get a string.

string_booleanI made a work around by replacing the text boolean by a real boolean:

 real_booleanHas anyone figured out how to handle a boolean without the need of replacing?

Best answer by david_r

Try casting to a boolean datatype in the JSONTemplater:

{
  "istrue": xs:boolean(fme:get-attribute("istrue"))
}

The attribute should either contain an integer (0 or 1) or the string "true" / "false".

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.

3 replies

david_r
Celebrity
  • 8392 replies
  • Best Answer
  • March 10, 2021

Try casting to a boolean datatype in the JSONTemplater:

{
  "istrue": xs:boolean(fme:get-attribute("istrue"))
}

The attribute should either contain an integer (0 or 1) or the string "true" / "false".


michielschram
Contributor
Forum|alt.badge.img+6
  • Author
  • Contributor
  • 16 replies
  • March 10, 2021

Thanks @david_r​. Works like a charm.

solution_booleanDo you have link to the documentation where this wisdom is documented?


david_r
Celebrity
  • 8392 replies
  • March 10, 2021

Thanks @david_r​. Works like a charm.

solution_booleanDo you have link to the documentation where this wisdom is documented?

I don't think it's documented in FME, you'll have to look it up in one of the many XQuery documentations online, e.g. https://docs.oracle.com/cd/E13214_01/wli/docs92/xref/xqtypecon.html#wp1118764