Hi there, I’ve got a datatable that I’ve imported from CSV. A column in the table is an amount (Int32). When I serialize the dt, the result has the amount converted to a string. I’m using: “jsonConvert.SerializeObject(outputFinal)” for the conversion.

Here’s an example:
“date”: “2019-08-30”,
“payee”: "SERVICE CHARGE ",
“memo”: “”,
“amount”: “-200” ,

I’ve be super grateful for any advice on how I can prevent the value from being converted to a string?

Hi @pattyricarte

The dt is already converted to a Json Object, the problem is the “amount” property is showing “-200” as a string - I need it to be an int ie, -200 (no “”)

The strange thing is the amount is an int in the data table so I don’t understand why it’s being converted to a string.

Thanks - does that mean I need to iterate through the entire JsonObject and convert each value in the “amount” property one at a time, or is there a way to convert all the “amount” properties at once?

"date": "2019-08-30", "payee": "GOV STAMP DUTY ", "memo": "", "amount": "-100", "account_id": "f21b0dd44" "date": "2019-08-30", "payee": "COMPLIANCE FEE ", "memo": "", "amount": "-200", "account_id": "f21b0dd44" "date": "2019-08-30", "payee": "TO: CHARLES N JACKSON-Salary transfer", "memo": "", "amount": "-800000", "account_id": "f21b0dd44"

I’m not sure I understand. The datatable has the amount set to Int32 already. The Serialize converts the amount to a String which is not what I want.

Should I first convert the datatable to a jsonArray and then serialize it to get all the ‘amount’ fields converted to Int32?

This is the result I’m after:

“date”: “2019-08-30”,
“payee”: "GOV STAMP DUTY ",
“memo”: “”,
“amount”: -100,
“account_id”: “f21b0dd44”
“date”: “2019-08-30”,
“payee”: "COMPLIANCE FEE ",
“memo”: “”,
“amount”: -200,
“account_id”: “f21b0dd44”
“date”: “2019-08-30”,
“payee”: “TO: CHARLES N JACKSON-Salary transfer”,
“memo”: “”,
“amount”: -800000,
“account_id”: “f21b0dd44”

Hello @cnjackson
I tried your code jsonConvert.SerializeObject(outputFinal) and it is working fine.
Please make sure the datatype of column amount is integer and not string.

@cnjackson No need to convert it to data table .Just pass the text file and serialize and it will return an object. Then do this Convert.ToInt32(Jsonobject(“PropertyName”))

Have you already try it ?

cheers :smiley:

Happy learning :smiley:

Log In using your UiPath Account to:

• get help with your automation projects
• share feedback, report bugs or just drop
us any question
• become an MVP and get access to
exclusive events
• save your user preferences like themes
and more
• automatically sign in to other services
• get in touch with our Forum staff