0

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 :)

4
  • Why don't you chose to convert it into an object using jackson or java api ? Commented Feb 8, 2016 at 17:27
  • 2
    Try parsing it into a JSONObject, and then truning it back to a String however you like. I prefer using JSONSimple but thats up to you to decide :- ) EDIT: There may be a suffisticated way to do it through regex's that i am not aware of. Commented Feb 8, 2016 at 17:28
  • Take a look at this http://stackoverflow.com/questions/21879568/remove-quote-from-the-jsonarray-output Commented Feb 8, 2016 at 17:34
  • If I convert to an object, the problem is, since the values are quoted it is still recognized as a String, no matter what data type actually is in there Commented Feb 10, 2016 at 10:36

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.