Slee
Slee

Reputation: 28258

Remove strange hidden charecters from my JSON before deserializing

I have some JSON being sent to me that breaks when it is trying to be deserialized. It seems to contain a black diamond with a ? in it. I cannot see the character but it is obviously there and it is failing on my system.

How do I get rid of this and still leave my JSON intact for deserialization?

UPDATE:

Here is a example of what will be in the middle of my JSON:

"UDF5" : "�65",

I am even open to just removing this property from my JSON altogether via RegEx.

Upvotes: 0

Views: 400

Answers (1)

Matthew
Matthew

Reputation: 9949

As answered for: remove piece of string (JSON string ) with regex and based on the formatting you provide in that question (and I am assuming will edit into this one):

Assuming I can rely on the formatting you show above and it is one of these per regex being run this can be accomplished as simply as something like

([\S\s]*\"])\"UDF5\" : \"[\S\s]*?\",([\S\s]*)

Using the back reference $1$2 referencing the parts before and after the UDF5 field to write back out.

If there is a newline there to remove I am not doing it right now. This could be better - if someone else has time to correct or provide an additional answer. But in the interests of getting you an emergency fix I hope this helps.

Upvotes: 1

Related Questions