you should check if the type of the payload (the message in that case) is an array or object. If that is the case, theres no other meaningful way than to encode it with json_encode. The type should only handle the xml case i think.