Q:

Reading messy JSON using php

Hello I've got this really messy JSON that I would like to read data from but I can't think of a way to do it.
It looks like this
https://pastebin.com/55pWWgnK
  {
    "capacity_test": {
      "date": "2017-03-01",
      "status": "done",
      "PROPERTIES": {
        "fail": {
          "capacity_test": {
                    .
                    .
                    .
          },
          "def": [
            {
              "drop_test": {
                "Properties": {
                  "date": "2017-03-05",
                  "status": "done"
                }
              },
              "waves_test": {
                "date": "2018-03-06",
                "status": "done"
              }
            },
            {
              "drop_test": {
                "Properties": null
              },
              "waves_test": {
                "date": "2018-03-06",
                "status": "done"
              }
            },
            {
              "drop_test": {
                "Properties": null
              },
              "waves_test": {
                "date": "2018-03-06",
                "status": "done"
              }
            }
          ]
        },
        "final_test": {
          "Properties": null
        }
      }
    }
  }

PROPERTIES is not the same as Properties and this json array is recursive, it can have infinite amount of "capacity_test" inside one another.
My issue is that I would like to check if there is a "status" key with no value in there somewhere.
This JSON is quite messy, I tried to come up with a recursive php function such as:
$this->myFunction($json, 'capacity_test');
public function myFunction($json, $step, $status = 0)
{
    if ( is_object($json->$step) ) {
        if ( isset($json->$step->status) ) {
            if ( !empty($json->$step->status) ) {
                $status = 1;
            }
        } else {
            foreach ( $json->$step as $item ) {
                if ( is_object($item) ) {
                    $status = $this->myFunction($item, $step, $status);
                    if ( $status === 0 ) {
                        exit(0);
                    }
                }
            }
        }
    }

    return $status;
}

This doesnt seem to work for me

A:

This piece of code should help you. Implement your own logic, when status is empty.
<?php

$jsonString = '{
        "capacity_test": {
          "date": "2017-03-01",
          "status": "done",
          "PROPERTIES": {
            "fail": {
              "capacity_test": {
                "date": "2017-03-02",
                "status": "done",
                "PROPERTIES": {
                  "boolean": false
                }
              },
              "def": [
                {
                  "drop_test": {
                    "Properties": {
                      "date": "2017-03-05",
                      "status": "done"
                    }
                  },
                  "waves_test": {
                    "date": "2018-03-06",
                    "status": "done"
                  }
                },
                {
                  "drop_test": {
                    "Properties": null
                  },
                  "waves_test": {
                    "date": "2018-03-06",
                    "status": "done"
                  }
                },
                {
                  "drop_test": {
                    "Properties": null
                  },
                  "waves_test": {
                    "date": "2018-03-06",
                    "status": ""
                  }
                }
              ]
            },
            "final_test": {
              "Properties": null
            }
          }
        }
      }';

$ar = json_decode($jsonString);

function recArr($array) {
    foreach ($array as $k => $v) {
        if (is_array($v) || is_object($v)) {
            recArr($v);
        } else {
            if ($k == 'status' && $v == '') {
                // some empty logic
                echo $k;
            }
        }
    }
}

var_dump(recArr($ar));

