Skip to main content
Solved

JSON Extractor, but problems with the source JSON

  • February 15, 2024
  • 1 reply
  • 132 views

dustin
Influencer
Forum|alt.badge.img+31

I’m dealing with a rather large JSON file. The issue I have is that some element values contain literal quotes and double quotes, and these are causing Rejections in the JSONExtractor. The quotes/double quotes are not escaped in the original source. Is there a way to escape these automatically with other FME JSON transformers?

My efforts to fix thus far using the StringReplacers have resulted in errors throughout the entire JSON string, since quotes/double quotes are native to JSON formatting.

Best answer by debbiatsafe

Hi @dustin,

Unfortunately, there are no JSON-specific transformer that will create valid JSON from invalid JSON.

A series of StringReplacers should be an option if the JSON file isn’t too complicated. One way to do this would be to first identify all syntactically-valid double-quote characters and replace with different character(s). Then escape all remaining double-quotes with a backslash and turn the replacement characters (step 1) back into double-quotes.

You can also do string replacements by using a PythonCaller with the re (regular expression) module (eg. something like this).

I have attached an example workspace with both of these approaches. The StringReplacer method may need further work depending on the structure of your JSON.

Of course, the easiest way would be to get a version of the file with valid JSON.

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

1 reply

debbiatsafe
Safer
Forum|alt.badge.img+20
  • Safer
  • Best Answer
  • February 21, 2024

Hi @dustin,

Unfortunately, there are no JSON-specific transformer that will create valid JSON from invalid JSON.

A series of StringReplacers should be an option if the JSON file isn’t too complicated. One way to do this would be to first identify all syntactically-valid double-quote characters and replace with different character(s). Then escape all remaining double-quotes with a backslash and turn the replacement characters (step 1) back into double-quotes.

You can also do string replacements by using a PythonCaller with the re (regular expression) module (eg. something like this).

I have attached an example workspace with both of these approaches. The StringReplacer method may need further work depending on the structure of your JSON.

Of course, the easiest way would be to get a version of the file with valid JSON.


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