T.S
T.S

Reputation: 51

I need to remove a piece of every line in my json file

I have a json output on my notepad and i know it is not in the correct format. At the end of each line there is a time stamp which is causing the bad format. I want to get rid of it using find and replace since the file is pretty big. The format is as follows :

"eventtimestamp": "05 23 2017 04:01:02"}

The above piece comes in at the end of every line. How can i get rid of it using find a replace or any other way.

All help is appreciated. Thank you

Upvotes: 1

Views: 1674

Answers (2)

Jacques Bounliphone
Jacques Bounliphone

Reputation: 39

If you are not sure that the eventtimestamp field always comes in at the end of a line and/or as the last element of the object, prefer that kind of pattern: "eventtimestamp":\s*"[^"]+",?.

Note the useful surrounded excepted character class pattern "[^"]+" that can be declined with any other delimiter.

Upvotes: 0

STW
STW

Reputation: 46366

If you need to alter every line in a consistent way then regex find/replace is a good option. Free tools like atom.io, Notepad++, and plenty of others offer this feature.

Assuming "eventtimestamp" is constant, then a simple regex that says "find everything starting with "eventtimestamp" and up to a '}'" will work.

"eventtimestamp".*(?=})

And "replace" that with an empty string.


ps) here's a demo of the regex in regexr.com--hovering over the parts of the pattern will explain what they do.

Upvotes: 2

Related Questions