使用php获取json模式的所有元素

I really need help on this one.

I have the following Json Schema:

{
    "url": "http://www.google.com",
    "bodySchema": {
        "type": "object",
        "properties": {
            "SKU": {
                "sync": "True",
                "mapTo": "SKU",
                "type": "string"
            },
            "WareHouseId": {
                "sync": "False",
                "mapTo": "",
                "type": "integer"
            },
            "Stock": {
                "sync": "True",
                "mapTo": "Stock",
                "type": "integer"
            }
        },
        "required": {
            "0": "SKU",
            "1": "Stock"
        }
    }
}

I would like to retrieve all elements and check if they are required or not,

On the first part (Getting all elements)

What I'm doing is:

foreach ($this->methods as $data) {
    if(!empty($data['bodySchema']->properties)){
    }
}

But my problem is that I have no way to get the SKU, WarehouseID or Stock, because it's not a key nor anything of the kind.

For my second issue what I was thinking, was to put all required as string and do a loop through them, but if there is any alternative would be glad to know.

You can get the properties out with a simple loop:

foreach ($data->bodySchema->properties as $key => $value) {
    // ..
}

If you want to add the required field to the results from above, you can do it like so:

foreach ($data->bodySchema->required as $required) {
    $data->bodySchema->properties->$required->required = true;
}

Example with objects or with arrays.