I'm trying to match JSON condition strings in Java and have been hitting my head against a wall trying to find a solution. In these condition strings, conditions are JSON objects "{}", which may be evaluated on their own, or in a group. These groups are represented as arrays of condition objects "[]". I had a solution that worked fine to match the contents between characters for groups and objects respectively, however, this went out the window when I attempted to store groups inside other groups.
Example string:
[{"field":"type","operand":"=","value":"column"}, "&&",
[{"field":"type","operand":"=","value":"column"}, "||",
{"field":"type","operand":"=","value":"column"}], "||",
{"field":"type","operand":"=","value":"column"}]
The intended outcome was to match the contents of the string between (and including) the characters [ and ].
I've worked out that what I need is to match the contents of [ ... ] until there is a ] that is not followed (somewhere ahead, i.e., .+?) by another ] before a [. Doing a lazy search for ] will stop the match at the first occurence, but doing a greedy match will match the entire string up to the last occurence, which may contain many other groups/objects. I've experimented with lookbehinds/lookaheads, but these require statically defined character positions, and cannot stretch to find (or not find) an occurence of a character.
At this point, I'm stumped and would greatly appreciate any advice you have to offer.