Vienna Vienna - 3 months ago 10
JSON Question

JSON: Adding missing quotes and commas automatically in WebStorm

I get from a service json-like-data with several hundred different structures:

car112: {
n: Audi
type: A4 20 TDI ultra daylight
sd: 01.07.2016
p: 34216
st: false
car113: {
n: BMW
type: not known
st: true

and want to get quotes and commas automatically added in WebStrom, so that I have a valid json file afterwards:

"car112": {
"n": "Audi",
"type": "A4 2,0 TDI ultra daylight",
"sd": "01.07.2016",
"p": 34216,
"st": false
"car113": {
"n": "BMW",
"type": "not known",
"st": true

How could I do that easily?


There is 'Wrap with double quotes' quickfix available on Alt+Enter: Alt+Enter, Right, Fix all 'Compliance with JSON standard problems in file. But unfortunately it doesn't correctly work for values with words separated with white spaces/dots (WEB-22240). And it doesn't allow adding missing commas. So it seems that your only option is using Find/Replace with regexp