Hey Delegate
Wau this was a learning experience for me
I hope the solution solve your needs.
Solution - Regex - String with multiple matching keys.json (16.2 KB)
Solution
What the provided solution does is split up the text-sting into key : value pairs of groups of four (4), since they are repeating themself.
Then they are split-up again, mapping key : value pair to a collection keys and values.
So in short, what you go from having is…
A string like this, with multiple key’s named the same:
"MES": "Septiembre 2024","CÓDIGO 020": "No encontrado","CÓDIGO 124": "No encontrado","CÓDIGO 538": "No encontrado","MES": "Agosto 2024","CÓDIGO 020": "No encontrado","CÓDIGO 124": "No encontrado","CÓDIGO 538": "294426","MES": "Julio 2024","CÓDIGO 020": "No encontrado","CÓDIGO 124": "No encontrado","CÓDIGO 538": "294632"
To groups of 4 key : value pairs, like this:
"MES": "Septiembre 2024","CÓDIGO 020": "No encontrado","CÓDIGO 124": "No encontrado","CÓDIGO 538": "No encontrado",
"MES": "Agosto 2024","CÓDIGO 020": "No encontrado","CÓDIGO 124": "No encontrado","CÓDIGO 538": "294426",
And down to an array of collections of key:value pairs
[
{
"array": [
{
"key-value": {
"MES": "Septiembre 2024",
"CÓDIGO 020": "No encontrado",
"CÓDIGO 124": "No encontrado",
"CÓDIGO 538": "No encontrado"
}
},
{
"key-value": {
"MES": "Agosto 2024",
"CÓDIGO 020": "No encontrado",
"CÓDIGO 124": "No encontrado",
"CÓDIGO 538": "294426"
}
}
]
}
]
Hope this is useful. It sure did take some time for me, this one.
But a great opportunity to learn something.
A big thanks to @samliew for a solution provided in another post. It really really help me on my way.
Link: Text Parser bundles to JSON object - How To - Make Community
Regex used:
1st text parser:
(?:[^,]*,|[^,]*$){4}
2nd text parser:
(?<key>[^"]+)":\s*"(?<value>[^"]+)
Resources: