Skip to main content
Best Answer

How to remove characters from JSON list?

  • September 6, 2021
  • 4 replies
  • 281 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 

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.

4 replies

geomancer
Evangelist
Forum|alt.badge.img+60
  • 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

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+60
  • Evangelist
  • Best Answer
  • September 7, 2021

For ["Easy","Advanced"] use

\[|"|\]

Regex_brackets_quotes_2 


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

For ["Easy","Advanced"] use

\[|"|\]

Regex_brackets_quotes_2 

Yes this worked, thank you!