Regular Expressions 101

Community Patterns

JSON Double Quoting

0

Regular Expression
ECMAScript (JavaScript)

/
({|,)?\s*'?([A-Za-z_$\.][A-Za-z0-9_ \-\.$]*)'?\s*:\s*
/
g

Description

Insert double quotes between matches around colons. You need to wrap substition.substr(1)+'"' with parenthesis afterwards. (substr is needed to remove hanging doublequote at the start of the string)

ex) var json = '{ '+json_ish.replace(regex,subs).substr(1)+'" }';

I made this regex to validate and parse google spreadsheet's json-ish feed.

Please use with care, this is not tested througly.

inspired from http://stackoverflow.com/a/25146087

Submitted by anonymous - 8 years ago