Transforming API objects in JSON
Hello,
When I retrieve objects from the API, (i.e api.list_namespaced_config_map(namespace)), I get an output not JSON serializable because all keys are single quoted instead of double quoted:
{'api_version': 'v1', 'items': [{'api_version': None, 'data': {} 'kind': None, 'metadata': {'annotations': None, 'cluster_name': None, 'uid': 'c57fbrtrtrtrttrrtr60b9f3cc7b9'}}], 'kind': 'ConfigMapList', 'metadata': {'resource_version': '287723763', 'self_link': '/api/v1/namespaces/blabla'}}
Is it an intended behaviour? In that case, how could I process API objects to be used and manipulated as JSON? There is also an issue with None values not double quoted. I'm sure it is a newbie question but I don't know what to do.
Thank you for your help.
See #390, and you can try using json.dump for serializing to JSON.
Hi @allanadair,
Thank you very much! This works like a charm!
I would never have been able to find it by myself...
Sincerely,
Lain92
I tried doing a json.dumps() but got this
abc=api3.list_ingress_for_all_namespaces()
jabc = json.dumps(abc)
TypeError: Object of type 'ExtensionsV1beta1IngressList' is not JSON serializable
I tried doing json.dumps() but I got this v1 = client.CoreV1Api() ret = v1.list_node() nodelist = json.dumps(ret)
TypeError: Object of type 'V1Node' is not JSON serializable
Hey
Take a look at this comment.
preload_content is probably what you want there.