Skip to main content
Solved

How to remove characters from JSON list?

  • September 6, 2021
  • 4 replies
  • 235 views

Forum|alt.badge.img

I'm really struggling with the string functions in FME at the moment. I have a workbench reading JSON features from an API and I have one attribute where the results are in a list. The JSON extractor results the attributes like this:

 

["Medium"]

 

Or if there are multiple values, like so:

["Easy","Advanced"]

 

I want the results to be:

Medium

Intermediate,Easy

 

I want to remove the brackets and quotes using a single transformer and can't figure out the formatting for my life! Currently I have 3 separate "string replacers", each one removing a single character, but there must be a better way...I don't mind using a REGEX expression if someone can figure it out. I'm also open to using a different type of JSON query to extract these values? If there's a way to get the attributes without the brackets and quotes?

 

I also tried using the string pair replacer but I constantly get an error, and I can't seem to format it properly. I wish you could enter the pairs in table format instead of one long string for replacements...would make it so much easier to figure out!

 

Any advice would be appreciated 🙂

Best answer by geomancer

For ["Easy","Advanced"] use

\[|"|\]

Regex_brackets_quotes_2 

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

4 replies

geomancer
Evangelist
Forum|alt.badge.img+48
  • Evangelist
  • September 7, 2021

Edit: The original question asked how to process ["Intermediate"],["Easy"]

\["|"\]

in a StringReplacer in regex mode does the trick. The brackets need to be escaped.

Regex_brackets_quotes 


Forum|alt.badge.img
  • Author
  • September 7, 2021
geomancer wrote:

Edit: The original question asked how to process ["Intermediate"],["Easy"]

\["|"\]

in a StringReplacer in regex mode does the trick. The brackets need to be escaped.

Regex_brackets_quotes 

Thanks for your response! Apologies, I did mess up a bit in my question though...the input is ["Easy","Advanced"] I've just updated in the question...

 

Your expression works but doesn't remove the inner quotes. I'm no regex expert so I still have no idea how to fix this unfortunately. If you know how to remove the inner quotes as well that would be great!


geomancer
Evangelist
Forum|alt.badge.img+48
  • Evangelist
  • Best Answer
  • September 7, 2021

For ["Easy","Advanced"] use

\[|"|\]

Regex_brackets_quotes_2 


Forum|alt.badge.img
  • Author
  • September 7, 2021
geomancer wrote:

For ["Easy","Advanced"] use

\[|"|\]

Regex_brackets_quotes_2 

Yes this worked, thank you!


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