I'm having troubles with trying to get city_id extension attribute from a RateRequest object to use it with in_array PHP function, but I'm getting: Cannot use object of type Magento\Quote\Api\Data\AddressExtension as array

The thing is that I've a logger set and doing json_encode($request->getData()) returns the following JSON:


As you can see, there's city_id value on extension_attributes key, assuming json_encode return a string, I tried to get with $request['extension_attributes']['city_id'] but it's returning the error. How is that possible? I'm doing something wrong?

Thanks in advance!

2 Answers 2


You have converted it to json_encode, if you want to get it as $request['extension_attributes']['city_id'] then you need to use json_decode to decode the returned json function first


In your first json_encode it change first level json to array but city is again it slef an object "extension_attributes":{"city_id":"903"} either again use json_encode or use like following

$request['extension_attributes']->city_id to get city value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.