Skip to main content
Solved

StringReplacer - Regex on json formatted text

  • November 10, 2017
  • 2 replies
  • 30 views

timboberoosky
Contributor
Forum|alt.badge.img+7

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

takashi
Celebrity
  • 7843 replies
  • 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+7
  • Author
  • Contributor
  • 50 replies
  • November 13, 2017

Thank you very much, this works perfectly!