Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing a malformed jSon string

Tags:

java

json

I'm using a Java Json library to convert an incoming string into a json one. The lib is json-lib.

The problem is that I can't modify the source so, sometimes I can get some malformed jSon strings especially this kind of key/value strings :

"key":"a quoted "value" "

(this is a simplified example)

As you can see, there are double quotes surrounding the value.

So, is there an API that can replace automatically the inner double quotes with backslash ones?

Thank you.

like image 553
Pen Avatar asked Jul 05 '26 08:07

Pen


1 Answers

Well, there can't be. For example, what does the following (malformed example) mean:

"key":"is this a value?","another key":"is this a value too?"

In your condition it might be either:

"key":"is this a value?","another key":"is this a value too?"
^k1   ^v1                ^k2           ^v2

or:

"key\":\"is this a value?\",\"another key":"is this a value too?"
^k1                                        ^v1
like image 123
MByD Avatar answered Jul 06 '26 22:07

MByD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!