It looks like your use case might be similar to the one I tried to answer in another thread here: Convert string to nested structure. Do any of those solutions work for you?
It looks like your use case might be similar to the one I tried to answer in another thread here: Convert string to nested structure. Do any of those solutions work for you?