Refactor JSON serializer to use _getMappedKey

Before we used to lookup the key from attrs hash every time manually
which was error prone. Now we use _getMappedKey to lookup the key.