Parsing complex JSON with Python

Yakir Mordehay

I'm quite new with JSON and Python and trying to work with complex JSON outputs that I'm getting with GET requests. This is one example of JSON output (this is a small part of it but the principle is the same):

{
  "innerSet": [
    {
      "clusterUID": {
        "id": 3585057579401361143
      },
      "rpasState": [
        {
          "rpaUID": {
            "clusterUID": {
              "id": 3585057579401361143
            },
            "rpaNumber": 1
          },
          "status": "OK",
          "repositoryConnectivityStatus": {
            "accessStatus": "OK",
            "multipathingProblems": false
          },
          "remoteRPAsDataLinkStatus": [
            {
              "JsonSubType": "RPAConnectivityStatus",
              "clusterUID": {
                "id": 2671811049708195677
              },
              "entityType": "RPA",
              "connectivityStatus": "OK",
              "rpaUID": {
                "clusterUID": {
                  "id": 2671811049708195677
                },
                "rpaNumber": 1
              }
            }
          ],
         }
      ]
    }
 ]
}

I trying to find the best way to print a single value. For example, I need the value of "connectivityStatus". Any help will be much appreciated.

I able to pars simple JSON output. I have managed to get the entire innerSet tree:

x = requests.get('website.com)
d = x.json() print (d['innerSet']) 

However, I'not able to go the lower keys. For example, getting the value for "id" key in "clusterUID":

print (d['innerSet']['clusterUID']['id']) 

Results in the following error: TypeError: list indices must be integers, not str

Regards, Yakir.

rkrzr

You can do this:

import simplejson as json
data = json.loads(s)
print data['innerSet'][0]['rpasState'][0]['remoteRPAsDataLinkStatus'][0]['connectivityStatus']

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Parsing complex JSON with Python

From Dev

Parsing complex JSON with $.each()

From Dev

Parsing complex JSON with Go

From Dev

Complex json tree parsing

From Dev

Complex json tree parsing

From Dev

Parsing complex and changing JSON data in Python, several levels deep

From Dev

Parsing complex and changing JSON data in Python, several levels deep

From Dev

Parsing a complex JSON object with Python: search a specific key/value pair

From Dev

IOS Complex JSON Structure Parsing

From Dev

Parsing Complex JSON Response in PHP

From Dev

Parsing Complex Mathematical Functions in Python

From Dev

Parsing complex JSON text with Json.NET

From Dev

Parsing complex JSON with JSON Combinators in Play

From Dev

best practice for parsing a complex json string

From Dev

Parsing a complex Json Object using GSON in Java

From Dev

complex json parsing not found exception java

From Dev

Java Complex JSON parsing (variable fields)

From Dev

Parsing Complex Json with Gson Java - Only nodes

From Dev

Parsing a nested and complex JSON response in C#

From Dev

Python: Parsing a complex string into usable data for analysis

From Dev

Python argparse: Complex Argument Parsing Scenario

From Dev

Parsing complex operands in boolean expressions in Python 2.7

From Dev

parsing json fields in python

From Dev

Parsing JSON in Python and AngularJS

From Dev

Parsing json in python

From Dev

Parsing formatted JSON with Python

From Dev

json parsing with python

From Dev

Error parsing JSON in python

From Dev

Parsing a .json file with Python