Fix issue #1231: JSONEncoder doesn't handle dict-like objects

Fix for #1231 - now check for ```__getitem__``` and then attempt to convert to a dict.
The check for ```__getitem__``` is there as there's no universal way to
check if an object is a mapping type, but this is a likely proxy