I have a json exported from Mongodb . It shows timestamp in a different format
"timestamp":{"$date":"2020-08-01T00:00:00Z"}} . I want to convert this timestamp object to a string like "timestamp":"2020-08-01T00:00:00Z" .
I have done this using sed like s/\{\"[$]date\":\"(\S{20})\"}/"\1"/g;. However , the length of the timestamp may vary if milliseconds are added to the time .Eg : "timestamp":{"$date":"2020-08-01T00:00:00.123Z"}} would be transformed with s/\{\"[$]date\":\"(\S{23})\"}/"\1"/g; , since the length of timestamp string is 23 characters. I want to convert this into a single transformation step where any length for the string would be good.
I can do this with jq too but that will need to read every line , store the value in a variable and use awk to change the value . This would be time consuming as compared to sed . So looking for a different solution.
A good answer would be really appreciated. Thanks