Replace quotes around JavaScript object properties

When pasting JSON with a lot of properties in a JavaScript file, I want to remove the double quotes around property names efficiently. How can I do it using WebStorm without deleting all quotes manually?

E.g.

{
"year": 2018,
"month": 9,
"day": 24,
"startHours": 6,
"startMinutes": 0,
}

 

should become

{
year: 2018,
month: 9,
day: 24,
startHours: 6,
startMinutes: 0,
}

0
5 comments

Replace (Ctrl+R) with regexp should help:

  • find "([^"]+)":
  • replace $1:


3

Thanks, this did the trick.

0

You can click inside the object and then click `cmd+.` (on mac) to "Show context actions"

And then select option "Unquote property names"

 

6

While this is handy it would be a perfect fit to be also configurable in Editor -> Code Style -> <Language> -> Punctuation
That way it could easily applied to multiple files or automatically applied when reformatting code.

1
Please feel free to create a new feature request here: https://youtrack.jetbrains.com/issues/WEB. We’ll see if it can be implemented.
0

Please sign in to leave a comment.