I need to extract one node value inside a particular node in a long JSON string.
i.e. description node of person node:
"person":{"age":"10", "description":"example",job:{"title":"sales","salary":"$3000"}, "sex":"male"}
As using a JSON library to deserialize a long JSON string wasted too much time, I googled and found a regex to match one JSON node value and it works fast most of the time (taking a few ms)
Regex regex = new Regex("\"person\":{(?:[^{}]|(?<open>{)|(?<-open>}))*\"description\":\"(.*?)\"(?:.*?)(?(open)(?!))}");
It works slowly (using a full second) when a duplicated node name exists in some inner node after the match happened for an unknown reason:
"person":{"age":"10", "description":"example", job:{"title":"sales", "salary":"$3000", "description":"example"}, "sex":"male"}
I want to improve this regex efficiency so that it will only check the outermost content for the person node (bolded):
"person":{"age":"10", "description":"example", job:{"title":"sales", "salary":"$3000", "description":"example"}, "sex":"male"}
I am new to regex, this regex may not suit my situation.
Any idea?