Skip to main content
Solved

JSON Extractor, but problems with the source JSON

  • February 15, 2024
  • 1 reply
  • 199 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.

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.

1 reply

debbiatsafe
Safer
Forum|alt.badge.img+21
  • 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.