-2

I have started using python and I am writing a code to get http json response, from the json response i want to filter, select the keys / object and print it. I am able to get the json response in the below format

{'name': 'M985533026-14742', 'instanceAttributes': '{"orgName":"0a1e554f-2d27-4516-811e-1ed74b192cdf","sessionUri":"://us-virginia-1-12.vchs.vmware.com/api/compute/api/sessions","apiVersionUri":"://us-virginia-1-12.vchs.vmware.com/api/compute/api/versions"}', 'dashboardUrl': '://us-virginia-1-12.vchs.vmware.com/api/compute/compute/ui/index_dr.html?orgName=0a1e554f-2d27-4516-811e-1ed74b192cdf&serviceInstanceId=c2343357-9578-4c38-85c9-4450ce08cda3&servicePlan=67538ff0-f4c3-48cb-8a6f-b0a3ac5aa324', 'description': 'M985533026-14742', 'apiUrl': '://us-virginia-1-12.vchs.vmware.com/api/compute/api/org/c2343357-9578-4c38-85c9-4450ce08cda3', 'instanceVersion': '1.0', 'id': 'c2343357-9578-4c38-85c9-4450ce08cda3', 'link': [], 'serviceGroupId': '5a7e5ae7-a6bc-4226-a5b6-844e7dd8c88e', 'region': 'us-virginia-1-12.vchs.vmware.com', 'planId': 'region:us-virginia-1-12.vchs.vmware.com:planID:67538ff0-f4c3-48cb-8a6f-b0a3ac5aa324'}, {'name': 'Virtual Private Cloud OnDemand', 'instanceAttributes': '{"orgName":"0e95ddcd-f1d8-4950-aaab-01c2b713f61f","sessionUri":"://us-california-1-3.vchs.vmware.com/api/compute/api/sessions","apiVersionUri":"://us-california-1-3.vchs.vmware.com/api/compute/api/versions"}', 'dashboardUrl':

Now I need to filter only the region and the orgName, Please help me ?

2
  • 1
    We won't write code for you, but if you have code of your own that is failing in ways you don't understand or if you have found some documentation confusing or have some other specific technical question we would be happy to help out. Commented Sep 6, 2017 at 17:36
  • Did you get a solution? Commented Sep 7, 2017 at 15:19

2 Answers 2

1

A JSON object is a dictionary. You could access:

res = yourjson['key']

if res is a dictionary too then:

final_res = res['other_key']

I hope this help you

Sign up to request clarification or add additional context in comments.

Comments

0

Access to the JSON like a dictionary:

if 'key' in json_object:
     result = json_object['key']

in the case of orgName you must write something like:

json_object['instanceAttributes'][orgName]

because is a dictionary within another dictionary.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.