Skip to main content

Hi all,

I have a set of JSON files which return an error upon trying to read them in - that it encounters an unexpected character "\\". If i open the JSON in a text editor and remove all the \\ characters it reads successfully in FME then.

As i have a batch of 300 JSON files i cant do this manually. I have tried reading in each one as a text file and using a StringReplacer but it is incredibly slow.

Has anyone got any suggestions or solutions?

Kind regards,

Jack

Can you post a sample JSON block that shows the context where the backslash occurs?

Be aware that the backslash has a specific meaning in JSON, and unless it's used correctly it's a sign of a malformed JSON document.

See also https://www.freeformatter.com/json-escape.html


Can you post a sample JSON block that shows the context where the backslash occurs?

Be aware that the backslash has a specific meaning in JSON, and unless it's used correctly it's a sign of a malformed JSON document.

See also https://www.freeformatter.com/json-escape.html

"[{\\"locationId\\":10,\\"customerId\\":0,\\"entityData\\":[{\\"entityID\\":4122,\\"locationID\\":10,\\"data\\":[{\\"dateTime\\":\\"2019-09-13T16:10:00\\",\\"reading\\":1.30286086,\\"quality\\":15},{\\"dateTime\\":\\"2019-09-13T16:15:00\\",\\"reading\\":1.27741158,\\"quality\\":15},{\\"dateTime\\":\\"2019-09-13T16:20:00\\",\\"reading\\":1.26401079,\\"quality\\":15},{\\"dateTime\\":\\"2019-09-13T16:25:00\\",\\"reading\\":1.25482106,\\"quality\\":15},{\\"dateTime\\":\\"2019-09-13T16:30:00\\",\\"reading\\":1.2469188,\\"quality\\":15},{\\"dateTime\\":\\"2019-.......


Can you post a sample JSON block that shows the context where the backslash occurs?

Be aware that the backslash has a specific meaning in JSON, and unless it's used correctly it's a sign of a malformed JSON document.

See also https://www.freeformatter.com/json-escape.html

The unescaping site works by the look. What is the issue then?


Looking at the sample you posted it looks like there's something wrong with the input JSON, it shouldn't be escaping all the quotes like that.

Try passing your JSON through a validator, e.g. https://jsonlint.com/ or the JSONValidator transformer in FME.

If the JSON document is indeed invalid, you have two choices: either manually clean it up or report it to whoever is responsible for the JSON files so that it gets fixed.


Can you post a sample JSON block that shows the context where the backslash occurs?

Be aware that the backslash has a specific meaning in JSON, and unless it's used correctly it's a sign of a malformed JSON document.

See also https://www.freeformatter.com/json-escape.html

In this context, the backslash is used as an escape character, which is why there are two backslashes to represent one.

Please note that the backslash has a special role in JSON for escaping characters, and if it's not used correctly, it could indicate malformed JSON.

For more details on handling backslashes in JSON, you can also refer to json escape for validation.


Reply