Nested data structures (like JSON) have to be parsed by relevant tools (e.g. json-aware here) in order to extract the information properly. Trying to operate on the nested data structures with line-aware routines only (like grep/sed/awk/etc), will produce failures and false positives. E.g., the above answer only would work if your JSON was pretty-printed having each JSON element one per line. Though it would fail if JSON was printed somehow else (i.e. in one line, or having multiple elements on the same line).
Thus, if you use python, you have to parse the object and then extract required data programmatically (i.e. write a script in python).
However, there's another approach: for unix there's a number or json-aware utilities developed to achieve the ask like yours quite easily, e.g. jq, jtc (and many others). Here, let me show you the solution based on jtc:
Assuming you have a following json:
bash $ cat file.json
then, in order to extract all the objects which contain
"test": "pi", using
jtc is like this:
bash $ cat file.json | jtc -w'[test]:<pi>: [-1]'
explanation on the walk-path (
[test]:<pi>: will find all elements like
"test": "pi" (if there are multiple)
[-1] will step up 1 JSON tier from found element(s).
resulting walk(s) will be printed.
jtc complete user guide here: https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md