Added json handling to postMessage()