Is there a regex expression I can use to find all the numbers in JSON string and replace them within double quotes?
For example in the below JSON string, I want to replace the Id and Phone values with double quotes.
String jsonString = " [
{
"FirstName": "abc",
"Email" : "[email protected]",
"Id" : 1,
"Phone" : 1234567890,
"Date": "2 May 2016 23:59:59"
},
{
"FirstName": "xyz",
"Email" : "[email protected]",
"Id" : 2,
"Phone" : 9876543210,
"Date": "3 May 2016 23:59:59"
}
] ";
I want to get the following output:
[
{
"FirstName":"abc",
"Email" : "[email protected]",
"Id" : "1",
"Phone" : "1234567890",
"Date": "2 May 2016 23:59:59"
},
{
"FirstName":"xyz",
"Email" : "[email protected]",
"Id" : "2",
"Phone" : "9876543210",
"Date": "3 May 2016 23:59:59"
}
]
I tried line below but it does not work. Any ideas?
jsonString = jsonString.replaceAll("=[ ]*([\\d]+)", "= \"$1\"");