Excuse me, but adding a custom key to the map to signal how to deserialize the JSON seems not to me a good practice. This way if you want to deserialize it to a
dict, you have to know that the JSON has that strange key, and remove it manually. If I see something in the code, I banter the coder If the code will broke because the company was so bold to update its Python version on its machines, well, I think they simply will remain to the previous Python version, or will fix the code.
Seriously, deserialization can’t know the type you want to deserialize.
json gives you set of standard conversions, and this is really handy. But if you want to deserialize to a custom type, you have to tell to the deserializer the custom type, as any decent JSON library in any language do.
If you want to magically deserialize your data in a custom object, you wrong the data type. You have to use XML + XSD, or a typed JSON, or something similar.
So, IMHO the correct way to deserialize the JSON to
MyMap is simply:
d = json.loads(json_data)
mm = MyMap(d)
This is because, unluckily,
json does not permit you to customize the conversion table. If this will be possible, not only you can directly convert JSON objects to
MyMap, but also arrays to
numpy.ndarrays, and so on. Buy I suppose this is another problem.