added json encoding as a fallback for XML encoding failure

Change-Id: I814f76645cf936ed7f18b837965d17ff4be9c440