Date and time formate chnaging after reading json and appending to new text file

hello,

My requirement is to read json and write as it is for date and time in newly created jsin file.
check below image.below is the original timedate format in file


when i am doing deserialize json and appending one by one line to another json file it is showing in below format

i want data as exact in 1 st image. As i am running automation on vm it is taking date fromat from vm.
if i am using below line in append line to write start date

" ““start””:“”“+Jrez(Counter4)(“start”).ToString+”“”“+”,"

Jrez(Counter4)(“start”).ToString - this is writing that value of date and time then what changes or additional thing i need to do in thi s so i can get as same as original

@Anil_G @Yoichi @lrtetala

Hi @Mathkar_kunal

Try this

" \"start\":\"" + Jrez(Counter4)("start").ToString("yyyy-MM-dd HH:mm:ss") + "\","

I hope it works!!

why u have put slash for start " "start":" this one ?

please check above error

its about the recognition that start is date with time info:

grafik

Kindly note:
instead of:

we used: ToString(“yyyy-MM-ddTHH:mm:ssK”)

1 Like

what showuld i modify in my line below one
" ““start””:“”“+Jrez(Counter4)(“start”).ToString+”“”“+”,"

was already shown:
grafik

Prototype it by yourself also within the immediate panel:
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

Please check this ss and update me

i made changes date is comming correct but issue in time . it is different
original


getting below
image

on my vm time is different that is causing issue?
please help what shoild i do in such case.

Hi @Mathkar_kunal

Try this:

"“start”:""" + DateTime.ParseExact(Jrez(Counter4)("start").ToString, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy-MM-dd HH:mm:ss") + ""","

in such case we turn off the dateparsing

Variable:

Assign Activity: myJSS.DateParseHandling =DateParseHandling.None

Instead of Deserialize JSON activity we do use an Assign Activity:
YourJOBjectVar = JsonConvert.DeserializeObject(of JObject)(YourJSONStringVar, myJSS)

then you can access the start date by: YourJOBjectVar(“start”).Value(Of String)

Samples, verfying the approach:
grafik

please check above error

please update if
" ““start””:“”“+Jrez(Counter4)(“start”).ToString+”“”“+”,"

this is my line then step by step actions
Jrez(Counter4)(“start”).ToString - contains data of date and time

@supriya117 any udpate?

not understood completely
what is yourJOobjvar and yourjsonstringvar

We assume that in your current modeling

  • the JSON text is anyhow present e.g. after read in a text file: YourJSONStringVar
  • that a deserialize JSON activity was used, having an output as a JOBject: YourJOBjectVar

We would also recommend to take a little break. Once you are coming back go through the mentioned model changes. Get an understanding of the touched building blocks (turning of DateParsing when deserializing the JSON String). So you will be able to do the modification in around 1 min and it should work.


is ia m doing correct some error
please update

ok i made changes again
look at below



error
please update

Maybe a Deserialize JSON Array was used within your origin modeling.

If so, then just change the deserialization setting to:
JsonConvert.DeserializeObject(of JArray)(YourJSONStringVar, myJSS)

JsonConvert.DeserializeObject(of JArray )(YourJSONStringVar, myJSS)

this need to assign to which variable?
need to create new varaible if yes then which datatype variable?
as i understood from your chat this need to assign to YourJOBjectVar variable
according to you “that a deserialize JSON activity was used, having an output as a JOBject: YourJOBjectVar”
if deserialize jason output value is already contains some data then what is the point to use same variable and assign different data?