Problem
Formal language theory shows that regular expressions are inappropriate for parsing JSON data: JSON is defined by a context-free grammar, but pure regular expressions are only capable of recognizing regular languages, which are lower in the Chomsky hierarchy. Regular expressions have a straightforward text representation, however, and that's why they were chosen at first.
Solution
JSONPath expressions also have text representations, but they are much more adequate for proper navigation and filtering of any JSON structure. Using the proper operators, it is also possible to check values for equality, for example.
As a side benefit, matching with JSONPath expressions renders minification unnecessary.
Implementation strategy
It looks like the jsonpath
npm package, and its jp.paths
function in particular, provides the functionality we are looking for to do payload matching based on JSONPath expressions.