Hi i have an issue with my current project where some of the json messages i recieve have escaped qu...
t
Hi i have an issue with my current project where some of the json messages i recieve have escaped quotes
"metaData":"{ \"source\":\"Urol. Oncol\"}",
how can i pre process this json content to remove the backslashes? i thought i could employ a custom serializer for this specific field however i cannot see how to achieve this is it possible to remove these backslashes?
a
Crikey, that’s an unusual problem. I don’t think KxS can help with that. I think you’d have to do some string manipulation before decoding it. If none of the strings contain
\"
then it’s an easy find-replace, if they might, then it’s a lot more tricky. If you can replace every
\"
with
"
, maybe lenient parsing will be able to handle it. What’s producing the invalid JSON?
t
@Adam S thanks for looking at this, thats what thought, the invalid json is produced by my organisations backend currenlty the only client is a javascript web site which doesnt seem to mind this data
a
any solution on your end will be 10 times more difficult than fixing the problematic backend :)
if you’re using Kotlin/JVM then maybe you could use the same JS parser https://stackoverflow.com/a/22856530/4161471 to parse the invalid-JSON, and return some valid JSON
t
I have requested they fix the backend, however i am not holding my breath 😄 the solution i employed was to treat the invalid json as a basic string then "parse" it using JSONObject into valid json to store in my database
a
i am not holding my breath 😄
I know that feeling! Sounds like you’ve found a good workaround