Home Ask Login Register

Developers Planet

Your answer is one click away!

olkoza February 2016

Java - How to convert values within JSON String (remove quotes on non-strings)?

I have a String, representing a JSON, e.g.

      {"someId":"2130706433","someValue":"Android","networkId":"0","someTag":"true", ...}

Now I want to remove the quotes, but only where I can (numbers and booleans). How do I best do this (in Java)?

Result should look like:

       {"someId":2130706433,"someValue":"Android","networkId":0,"someTag":true, ...}

Thanks for any help :)


jonk February 2016

You can do this with a fairly simple regex replace:

jsonString.replaceAll("\"([0-9]+|true)\"", "$1");

if every number and boolean in quotes is to be replaced.

Post Status

Asked in February 2016
Viewed 2,820 times
Voted 6
Answered 1 times


Leave an answer

Quote of the day: live life