How to convert json data into python object and replace invalid characters in keys such as spaces with valid characters for dot notation access

  json, namespaces, object, python

There is a good answer to How to convert JSON data into a Python object? but my JSON keys have invalid characters such as spaces and ":" in key strings.

Question is how to convert them to valid values so dot notation access can be used. For example {"key: 1":1} should be replaced with {"key__1"} so
obj.key_1 notation could be used. Note that replacing " " an ":" with "_" would make a valid object attribute name from an invalid name.

Source: Python Questions

LEAVE A COMMENT