Skip to main content

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.

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.


Reply