Consider this as my json string,
{"Table" : [{"userid" : "11","name" : "KumarP","designation" : "Business Head",
"phone" : "9789234793","email" : "[email protected]","role" : "Admin",
"empId" : "EI003","reportingto" : "KumarP"}]}
and i want to have my string like this,
{Table:[{ userid: "11", name: "KumarP", designation: "Business Head",
phone: "9789234793", email:"[email protected]", role : "Admin",
empId : "EI003",reportingto : "KumarP"}]}
I am doing so to use it with jlinq..
That makes the regex to remove the quotes from the keys MUCH easier. Start your solution with this: var cleaned = JSON. stringify(x, null, 2);
If you want to strip the quotes, just pipe the output from this command to tr -d '"' .
Use the String. replaceAll() method to remove all double quotes from a string, e.g. str. replaceAll('"', '') . The replace() method will return a new string with all double quotes removed.
To remove double quotes just from the beginning and end of the String, we can use a more specific regular expression: String result = input. replaceAll("^\"|\"$", ""); After executing this example, occurrences of double quotes at the beginning or at end of the String will be replaced by empty strings.
Use Regular Expressions:
var a='{"Table" : [{"userid" : "11","name" : "KumarP","designation" : "Business Head","phone" : "9789234793","email" : "[email protected]","role" : "Admin", "empId" : "EI003","reportingto" : "KumarP"}]}';
a=a.replace(/"(\w+)"\s*:/g, '$1:');
alert(a);
The string will become as your second codeblock:
{Table: [{userid: "11",name: "KumarP",designation: "Business Head",phone: "9789234793",email: "[email protected]",role: "Admin", empId: "EI003",reportingto: "KumarP"}]}
But won't that cause a problem if the label was a reserved word?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With