Hi team, @Yoichi, @ppr, et al;
I have a process in place that converts Json data to Data table so that certain fields are updated in an application from the data coming from each of the columns in the data table. This process has been in production and working seamlessly using the following expression
However, we wanted to revise the code as there was additional column required to be added - the column is Date column. All the rows of this column are not always need to be populated with date data, sometimes the rows could be empty or null. Therefore, we want the expression rewritten to handle this situation.
It looks like the issue arises from trying to convert empty strings to DateTime objects, which causes the deserialization to fail. To handle this, Maybe you can use a custom JsonConverter that treats empty strings as null for DateTime fields.
It seems data type of the column is DateTime and it doesn’t allow null or empty value.
As a workaround, how about either of the following?
Set something datetime value which cannot be in actual such as 2199-1-1
Then replace it to blank. In this case, it’s necessary to add a new column then copy theses values.
Insert dummy row which has all empty value as the first row in the json.
Then remove it from the datatable.
(Because datatype of columns is determined from the first row data)
Hi @Kancharla_Mahija -
Yes, you got the issue right. How do we do custom JsonConverter can you rewrite the expression I just posted in the initial post?
Not sure how it is done but your first suggestion [[quote=“Yoichi, post:3, topic:771087”]
Set something datetime value which cannot be in actual such as 2199-1-1
Then replace it to blank. In this case, it’s necessary to add a new column then copy theses values.
[/quote]
] looks like viable. It’d be great if you could show me how that’s done using the expressions - Also
Sorry I am not very much familiar with this, but do you want me to have them in invoke code subsequently. I guess my question is how it is implemented?
Since I am using REFramework (there is no currentrow)
I changed the expression to Newtonsoft.Json.JsonConvert.DeserializeObject(Of DataTable)( in_qi_TransactionItem.SpecificContent(“JsonStringIs”).ToString.Replace(“”“Date”“: “””“”, “”“Date”": ““2199-01-01T00:00:00"””)) and I still see the error
Hi @Yoichi and team,
I’ve another option to consider - which is replacing the date column with the row that has empty or null or “” replace with the current date (MM/dd/yyyy HH:mm:ss format). I used the following expression, Newtonsoft.Json.JsonConvert.DeserializeObject(Of DataTable)(in_qi_TransactionItem.SpecificContent(“JsonStringIs”).ToString.Replace(“”“Date”“: “””“”, “”“Date”“: “”” & Now.ToString(“MM/dd/yyyy HH:mm:ss”) & “”“”))
but I still see the issue not being resolved.
Just FYI - Not sure if it makes any difference but I have the assign activity of the above expression at the beginning of the Process Transaction of REFramework -
I ran and it works and types back to excel file. However, I have follow up questions.
Why do the remainder columns got cut off? As I need the sequence of the columns to be intact.
When I have to get the json from the queue item how do I have to do the breakdown you did? Using the initial expression we used Newtonsoft.Json.JsonConvert.DeserializeObject(Of DataTable)(in_qi_TransactionItem.SpecificContent(“JsonStringIs”).ToString.Replace(“”“Date”“:”“”“”, “”“Date”“:”“2199-01-01T00:00:00"”"))
Sorry for the multiple back and Forths - just wanted to fully understand and wanted to test my REFramework Sample20241004-1.zip (151.0 KB)
When I have to get the json from the queue item how do I have to do the breakdown you did? Using the initial expression we used Newtonsoft.Json.JsonConvert.DeserializeObject(Of DataTable)(in_qi_TransactionItem.SpecificContent(“JsonStringIs”).ToString.Replace(“”“Date”“:”“”“”, “”“Date”“:”“2199-01-01T00:00:00"”"))
To isolate cause, can you try to separate the expression then chek it step by step?
Then, check if the strJson doesn’t empty string value for Date key. If exists, investigate reason not replaced by the above expression. (e.g.extra white space etc.) Or share the part as file, if possible?