Ad
How To Parse Through A Nest Of Nested JSON?
I am stuck using this API at my work, and having trouble parsing through the dataset because of it's complexity.
In the following JSON, the only values of any importance to me are "name" and the actual host name. I am trying to make a dictionary that consists of {"name":"host, host, host, host"}. If anyone knows how to parse through this or can point me in the right direction, that would be very much appreciated.
{
"hugeData":[
{
"env1":[
{
"sins":[
{"host": "ip-10-12-138-225.va1.b2c.test.com", "deployTime": "2015-07-23 11:54 AM", "sin": "0"},
{"host": "ip-10-12-129-193.va1.b2c.test.com", "deployTime": "2015-09-01 01:09 PM", "sin": "7"},
{"host": "ip-10-12-138-235.va1.b2c.test.com", "deployTime": "2015-07-23 11:54 AM", "sin": "9"},
{"host": "ip-10-12-138-250.va1.b2c.test.com", "deployTime": "2015-07-23 11:53 AM", "sin": "12"},
{"host": "ip-10-12-138-223.va1.b2c.test.com", "deployTime": "2015-07-23 11:53 AM", "sin": "14"},
{"host": "ip-10-12-138-237.va1.b2c.test.com", "deployTime": "2015-07-23 11:54 AM", "sin": "17"},
{"host": "ip-10-12-138-244.va1.b2c.test.com", "deployTime": "2015-07-23 11:53 AM", "sin": "18"},
],
"status": "success",
"buildTime": "2015-05-26T17:06:06",
}
],
"name": "apache-6"
},
{
"env1":[
{
"sins":[
{"host": "ip-10-12-138-225.va1.b2c.test.com", "deployTime": "2015-12-16 05:23 PM", "sin": "0"},
{"host": "ip-10-12-129-193.va1.b2c.test.com", "deployTime": "2015-12-16 05:23 PM", "sin": "7"},
{"host": "ip-10-12-138-235.va1.b2c.test.com", "deployTime": "2015-12-16 05:23 PM", "sin": "9"},
{"host": "ip-10-12-138-250.va1.b2c.test.com", "deployTime": "2015-12-16 05:23 PM", "sin": "12"},
{"host": "ip-10-12-138-223.va1.b2c.test.com", "deployTime": "2015-12-16 05:23 PM", "sin": "14"},
{"host": "ip-10-12-138-237.va1.b2c.test.com", "deployTime": "2015-12-16 05:23 PM", "sin": "17"},
{"host": "ip-10-12-138-244.va1.b2c.test.com", "deployTime": "2015-12-16 05:23 PM", "sin": "18"},
{"host": "ip-10-12-138-248.va1.b2c.test.com", "deployTime": "2015-12-16 05:23 PM", "sin": "21"},
],
"status": "success",
"buildTime": "2015-12-16T17:07:44",
}
],
"name": "apache-5"
},
{
"env1":[
{
"sins":[
{"host": "ip-10-12-138-234.va1.b2c.test.com", "deployTime": "2015-08-06 03:13 PM", "sin": "10"},
{"host": "ip-10-12-138-246.va1.b2c.test.com", "deployTime": "2015-08-06 03:15 PM", "sin": "20"},
{"host": "ip-10-12-138-216.va1.b2c.test.com", "deployTime": "2015-08-06 03:04 PM", "sin": "28"}
],
"status": "success",
"buildTime": "2013-02-21T15:41:59",
}
],
"name": "app-steel"
},
}
Ad
Answer
Maybe you like the answer this time.
(assigned dict/json to a varibale named test)
your_dict = {i['name']: ", ".join([host['host'] for host in i['env1'][0]['sins']]) \
for i in test["hugeData"]}
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad