Skip to main content

Hello, I am reading some attributes from a database. Some are in string format, some in number (int, float etc.). I want to write these attributes to a json file.I noticed that all the attributes in string format are automatically output in quotation marks and the numbers without. In my case I have three attributes: district, lat and long. District is an int, lat and long are strings. How can I change lat and long so that their output is also without quotation marks like the district one (see image) ?

Hi @katt, you can use the stringformatter transformer. Use one of these options that meets your needs.

image--

If i've provided something helpful, please upvote the comment. If i've provided a solution, please mark it as 'Best Answer'. This helps the community find solutions when your question is referenced.

If I didn't provide a solution, please let me know if I can help further. Thanks! 🙂

 


Hi @katt, you can use the stringformatter transformer. Use one of these options that meets your needs.

image--

If i've provided something helpful, please upvote the comment. If i've provided a solution, please mark it as 'Best Answer'. This helps the community find solutions when your question is referenced.

If I didn't provide a solution, please let me know if I can help further. Thanks! 🙂

 

thank you @carmijo​ . I have already tried this. I used .2f in the string formatter and look at the output. It is still a string and not a float even though it has been reduced to two decimals.


thank you @carmijo​ . I have already tried this. I used .2f in the string formatter and look at the output. It is still a string and not a float even though it has been reduced to two decimals.

That's strange. have you tried running it through a second stringformatter with 'f' only?


thank you @carmijo​ . I have already tried this. I used .2f in the string formatter and look at the output. It is still a string and not a float even though it has been reduced to two decimals.

I just did it. No change in format though.


thank you @carmijo​ . I have already tried this. I used .2f in the string formatter and look at the output. It is still a string and not a float even though it has been reduced to two decimals.

very strange. from what i see, you're doing everything right. sorry i can't help further. might be worth opening a case with safe


How are you creating your json file?


How are you creating your json file?

I am using a JSON Templater. Maybe there is workaround to display the lat and long values without quotation marks?!


I am using a JSON Templater. Maybe there is workaround to display the lat and long values without quotation marks?!

You can do something like this

{
 
"district" : xs:int(fme:get-attribute("district")),
"lat": xs:float(fme:get-attribute("lat")),
"lon": xs:float(fme:get-attribute("lon"))
 
}

 

 


I am using a JSON Templater. Maybe there is workaround to display the lat and long values without quotation marks?!

Great. Thanks. I tried and it is the result I was looking for! are you good at datetime conversion as well ? I have it in this format "TIMESTAMP (string: UTF-8): 20221017174751.999" and I want the output to look like this format in the json:"timestamp": "2021-11-10T15:37:30+00:00". I used the DateTimeConverter but any parameters I was using, it is always rejected. Maybe you can help me out with this one as well?


I am using a JSON Templater. Maybe there is workaround to display the lat and long values without quotation marks?!

You need to set the TimeZone and then convert 

e.g.

@DateTimeFormat(@TimeZoneSet(@Value(date),+00:00),%Y-%m-%dT%H:%M:%S%z)

 


I am using a JSON Templater. Maybe there is workaround to display the lat and long values without quotation marks?!

@katt​ it's usually best to start a new question for a new topic. But this should work:imageMake sure your selecting an attribute (ellipsis) not an Attribute Value. You'll have to add the UTC Offset manually


I am using a JSON Templater. Maybe there is workaround to display the lat and long values without quotation marks?!

This works great. Thanks again.


I am using a JSON Templater. Maybe there is workaround to display the lat and long values without quotation marks?!

Hello @ebygomm​ , how can I limit the number of decimals to 4 ? In my case I only want 4 decimals after the point. If I use xs:float it adds some zeros sometimes, but I am not sure how I can limit the decimals numbers ? thank you.


Reply