Skip to main content
Solved

StringReplacer - Regex on json formatted text

  • November 10, 2017
  • 2 replies
  • 10 views

timboberoosky
Contributor
Forum|alt.badge.img+6

Hello,

I am trying to modify the contents of a series of json files, though I only need to remove all of the leading text before the "{"rings"" text. I will have upwards of 130 files to go through, and each has slightly different text to remove. I was thinking of using a StringReplacer to find all the text that I want to remove, then just set the "Replacement Text" to nothing. I'm assuming I need to use regex in the StringReplcaer to identify the series of text in each file that I need to remove. The example of text that I need to remove is:

{"displayFieldName":"","fieldAliases":{"OPS_AREA":"OPS_AREA","OBJECTID":"OBJECTID"},"geometryType":"esriGeometryPolygon","spatialReference":{"wkid":102100,"latestWkid":3857},"fields":[{"name":"OPS_AREA","type":"esriFieldTypeString","alias":"OPS_AREA","length":50},{"name":"OBJECTID","type":"esriFieldTypeOID","alias":"OBJECTID"}],"features":[{"attributes":{"OPS_AREA":"WINCHESTER","OBJECTID":12},"geometry":

though the "OPS_AREA" and "OBJECTID" values change between each file (obviously making the length of text I want to remove different between files). I am quite a noob on the regex front so I tried a number of things but really don't even have a clue as to what the syntax would be to remove this. I was thinking of using a StringReplacer to find all the text that I want to remove, then just set the "Replacement Text" to nothing.

I'm not opposed to using json readers or transformers either, but ultimately the output I need is just a text file with all the "rings" values (this specifically formatted text gets loaded into another database).

Any help would be greatly appreciates! Full disclosure - still using FME 2012!

Thanks

Tim

Best answer by takashi

Hi @timboberoosky, this regex matches one or more characters before '{"rings"'.

.+(?={"rings")

This worked in FME 2013+ (I don't have FME 2012 installation).

See here to learn more about the syntax: Regular-Expressions.info | Positive and Negative Lookahead

View original
Did this help you find an answer to your question?

2 replies

takashi
Evangelist
  • Best Answer
  • November 11, 2017

Hi @timboberoosky, this regex matches one or more characters before '{"rings"'.

.+(?={"rings")

This worked in FME 2013+ (I don't have FME 2012 installation).

See here to learn more about the syntax: Regular-Expressions.info | Positive and Negative Lookahead


timboberoosky
Contributor
Forum|alt.badge.img+6
  • Author
  • Contributor
  • November 13, 2017

Thank you very much, this works perfectly!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings