Say you were given the following JSON and you want the researchers
value to be an array instead of a string. We need to remove the quotes that are wrapping the array. In version 1.64 of VSCode, you can do this search and replace using the built-in search and replace regex capture groups (no extension needed).
[
{
"id": 2,
"description": "Project 1",
"researchers": "[12,5,22]"
},
{
"id": 3,
"description": "Project 2",
"researchers": "[1,44,22]"
}
]
In the search field you will want to use a regular expression of
"researchers": "\[(.+)\]"
, where the (.+)
part of the expression being the first group we want to preserve or leave unchanged when we perform the replace. Then in the replace field we use "researchers": [$1]
, with $1
corresponding to the (.+)
first group we are preserving in the search string. What this means is that we take the values that were found in the first search group (which in the first instance is 12,5,22
, then wrap it with "researchers": [
12,5,22]
.
The replaced JSON becomes:
[
{
"id": 2,
"description": "Project 1",
"researchers": [12,5,22]
},
{
"id": 3,
"description": "Project 2",
"researchers": [1,44,22]
}
]
The following video is also helpful. https://www.youtube.com/watch?v=6AsSfyHWWls