Home > Software design >  Issues creating a Json object that does not remove trail zeros
Issues creating a Json object that does not remove trail zeros

Time:04-08

I have successfully created a JSON object in snowflake with object_construct_keep_null The problem I am having is, the output removes any trailing zeros

 select "ID",
object_construct_keep_null('balcash',"cashBalance",'currency',"currency",'date',"createdAt") "Balance"

output is

{
  "balcash": 0.06,
  "date": "2022-04-06",
  "currency": "DKK"
}

Before creating the json object the value of balcash was 0.06000. I expect it to maintain the exact value. is there something I can do to ensure my values remain the same? expected json object.

 {
      "balcash": 0.06000,
      "date": "2022-04-06",
      "currency": "DKK"
    }

CodePudding user response:

If you want to maintain decimal precision, you'll need specify the precision and cast it to string before you construct the object

object_construct_keep_null('balcash',"cashBalance"::decimal(10,5)::varchar,
                           'currency',"currency",
                           'date',"createdAt")
  • Related