Here a solution using an Excel formula. Probably using FILTERXML
there is shorter way, but it is not available for Excel Web, which is the version I use. In cell B3
, you can use the following formula:
=LET(header, {"Group","Name"}, clean, SUBSTITUTE(TEXTSPLIT(B1,
{"[{","'key1': ","'key2':","}]","}, {"},,1),"),",")"),
split, WRAPROWS(clean,2), gps,INDEX(split,,2),names, INDEX(split,,1),
gpsUx, UNIQUE(gps), out, DROP(REDUCE("", gpsUx, LAMBDA(ac,x,
HSTACK(ac, VSTACK(header, HSTACK(x, FILTER(names, gps=x)))))),,1),
IFERROR(out,""))
Here is the output:

An alternative solution is using a recursive function to do all the replacement. Please check my answer to the question: Is it possible to convert words to numbers in a string without VBA? I use the same function here MultiReplace
:
= LAMBDA(text, old, new, IF(MIN(LEN(old))=0, text,
MultiReplace(SUBSTITUTE(text, INDEX(old,1), INDEX(new,1)),
IFERROR(DROP(old,1),""), IFERROR(DROP(new,1),""))))
where old
and new
are nx1
arrays, where n
is the number of substitutions.
The above function needs to be defined in the Name Manager since it is recursive. Now we are going to use in formula to provide the output of the question in cell B3
:
=LET(header, {"Group", "Name"}, clean, MultiReplace(B1,
{"{'key1': " ; ", 'key2':" ; "}" ; "[(";"]]";"], ("},
{"" ; "-" ; "" ; "(" ; "]" ; "] & ("}),
split, TEXTSPLIT(@clean,"-"," & "), gps,INDEX(split,,2),names, INDEX(split,,1),
gpsUx, UNIQUE(gps), out, DROP(REDUCE("", gpsUx, LAMBDA(ac,x,
HSTACK(ac, VSTACK(header, HSTACK(x, FILTER(names, gps=x)))))),,1),
IFERROR(out,""))
You can check the output of each name variable: clean
, split
, to see the intermediate results. Once we have the information in array format (split
), then we apply DROP/REDUCE/HSTACK
pattern. Check my answer to the question: how to transform a table in Excel from vertical to horizontal but with different length for more details.
Both solutions work for multiple groups, not just for two groups as in the input sample. For each unique key1
group it generates the Group and its corresponding Name columns and concatenate the result horizontally via HSTACK
.