Renaming multiple names?
-
Hi, I was wanting to rename the drivers in a json file and was wondering Is it possible to select multiple “driverName” “Names” and then paste in copied names from another text file. I will be doing this alot and up to 40 names at once, so the quicker the better.
eg. the following Jaime Baker / Steven Kourepenos / Jeff Rubinrenamed to Craig Lowndes / Mark Skaife / Russell Ingall
{
“drivers”: [
{
“driverName”: “Jaime Baker”,
“carDesign”: “21,fa7fed,000000,ffffff,fa7fed”,
“carNumber”: “1”,
“suitDesign”: “1,fa7fed,000000,ffffff”,
“helmetDesign”: “1,fa7fed,000000,ffffff”,
“carPath”: “mx5\mx52016”,
},
{
“driverName”: “Steven Kourepenos”,
“carDesign”: “0,111111,cccccc,ed1c24”,
“carNumber”: “2”,
“suitDesign”: “13,111111,cccccc,ed1c24”,
“helmetDesign”: “63,111111,cccccc,ed1c24”,
“carPath”: “mx5\mx52016”,
},
{
“driverName”: “Jeff Rubin”,
“carDesign”: “9,ffffff,1a4b9b,dff000”,
“carNumber”: “3”,
“suitDesign”: “23,ffffff,1a4b9b,dff000”,
“helmetDesign”: “35,ffffff,1a4b9b,dff000”,
“carPath”: “mx5\mx52016”,Cheers, Neil.
-
Is it possible to select multiple “driverName” “Names” and then paste in copied names from another text file
No, if it is meant to be like this
Having the names bob, john, sue in one file, select all and press copy
and in the other file you might select the names tim, nancy, susan and
you want to replace tim with bob, nancy with john and susan with sue.Yes, if you are willing to install a scripting language like python script
and the process of selection and copy follows a strict ruleYes if you want to use regular expression and you either are willing
to learn how it works, in case the file where the names are to be replaced
is looking different each time you want it to do,
or getting it done once right if the file looks always the same.Let us know if you want to go one of the mentioned ways.
-
@Ekopalypse Was hoping for the first option, My knowledge on such thigs is zero, so thanks for the reply, i’ll give it a miss.
-
@Ozzy-Neil said in Renaming multiple names?:
the first option
The problem with wanting that – well, not really the wanting (you are free to want anything your heart desires) – is that it is very specific to your exact need, and thus won’t be supported by any general purpose tool. Of course, if you write code, you can go ahead and code up your very specific need.
So, barring you writing that specific code, if you still need to accomplish your goal, I suggest you be flexible and consider the possibility of the other options (with a “Yes, if…”) that were offered. Sure, they are probably more complicated to use than your desired solution, but that’s the nature of it.
-
Hello, @ozzy-neil, @Ekopalypse, @alan-kilborn and All,
From that link, below, giving the general structure of the
JSONlanguage :https://www.json.org/json-en.html
Here is a work-around, using a regex S/R :
- First, at the very end of your
JSONfile, add this new JSON object, below :
{ "Steven Kourepenos": "Mark Skaife", "Jeff Rubin": "Russell Ingall", "Jaime Baker": "Craig Lowndes", }Note that the different couples
Old names: New names, added, are not necessarily, listed in the same order than in the file itself. Luckily, it does not matter ;-))-
Now, open the Replace dialog (
Ctrl + H) -
SEARCH
(?-s)("driverName":\x20)(".+?")(?=(?s:.+)^\2\h*:\h*(".+"))|(?s)\{[^{}]+\}\Z -
REPLACE
\1\3 -
Tick the
Match caseoption, if necessary -
Tick the
Wrap aroundoption -
Select the
Regular expressionsearch mode -
Click once on the
Replace Allbutton ( or several times on theReplacebutton )
So, assuming the original
JSONtest, with the new object containing all the couples of names, at the very end :{ "drivers": [ { "driverName": "Jaime Baker", "carDesign": "21,fa7fed,000000,ffffff,fa7fed", "carNumber": "1", "suitDesign": "1,fa7fed,000000,ffffff", "helmetDesign": "1,fa7fed,000000,ffffff", "carPath": "mx5\mx52016", }, { "driverName": "Steven Kourepenos", "carDesign": "0,111111,cccccc,ed1c24", "carNumber": "2", "suitDesign": "13,111111,cccccc,ed1c24", "helmetDesign": "63,111111,cccccc,ed1c24", "carPath": "mx5\mx52016", }, { "driverName": "Jeff Rubin", "carDesign": "9,ffffff,1a4b9b,dff000", "carNumber": "3", "suitDesign": "23,ffffff,1a4b9b,dff000", "helmetDesign": "35,ffffff,1a4b9b,dff000", "carPath": "mx5\mx52016", }, ... ... ... ... ... { "Steven Kourepenos": "Mark Skaife", "Jeff Rubin": "Russell Ingall", "Jaime Baker": "Craig Lowndes", }After clicking on the
Replace Allbutton, you should get the expected file :{ "drivers": [ { "driverName": "Craig Lowndes", "carDesign": "21,fa7fed,000000,ffffff,fa7fed", "carNumber": "1", "suitDesign": "1,fa7fed,000000,ffffff", "helmetDesign": "1,fa7fed,000000,ffffff", "carPath": "mx5\mx52016", }, { "driverName": "Mark Skaife", "carDesign": "0,111111,cccccc,ed1c24", "carNumber": "2", "suitDesign": "13,111111,cccccc,ed1c24", "helmetDesign": "63,111111,cccccc,ed1c24", "carPath": "mx5\mx52016", }, { "driverName": "Russell Ingall", "carDesign": "9,ffffff,1a4b9b,dff000", "carNumber": "3", "suitDesign": "23,ffffff,1a4b9b,dff000", "helmetDesign": "35,ffffff,1a4b9b,dff000", "carPath": "mx5\mx52016", }, ... ... ... ... ...
If this S/R does the job, I’ll tell you, next time, how this regular expression works… !
Best Regards,
guy038
- First, at the very end of your