Get the key for the second layer migration of JSON data in python

File example

For example, when you want to get the value using " ruleId " as a key

test.json


{
    "timestamp": 1604751455679,                                                                   
    "ruleGroupList": [
        {
            "ruleGroupId": "AWS#AWSManagedRulesCommonRuleSet",
            "terminatingRule": {
                "ruleId": "NoUserAgent_HEADER",
                "action": "BLOCK",
                "ruleMatchDetails": null
            },
            "nonTerminatingMatchingRules": [], 
            "excludedRules": null
        }
    ]   
}

How to take out

--Extract like jsn [" ruleGroupList "] [0] ["terminatingRule"] ["ruleId"]

import json

with open('test.json') as f:
    jsn = json.load(f)

print(jsn["ruleGroupList"][0]["terminatingRule"]["ruleId"])

Execution result

yuta:~ $ python jsontest.py 
NoUserAgent_HEADER

Recommended Posts

Get the key for the second layer migration of JSON data in python
Get the caller of a function in Python
The story of reading HSPICE data in Python
[Introduction to Python] How to get the index of data with a for statement
How to get the number of digits in Python
[python] Get the list of classes defined in the module
Get the size (number of elements) of UnionFind in Python
Not being aware of the contents of the data in python
Let's use the open data of "Mamebus" in Python
Get the URL of the HTTP redirect destination in Python
Get the value of a specific key in a list from the dictionary type in the list with Python
Try scraping the data of COVID-19 in Tokyo with Python
Check the operation of Python for .NET in each environment
[Understand in the shortest time] Python basics for data analysis
Get the number of occurrences for each element in the list
Google search for the last line of the file in Python
Get the index of each element of the confusion matrix in Python
Get Leap Motion data in Python.
Get data from Quandl in Python
Get the desktop path in Python
Get the value of a specific key up to the specified index in the dictionary list in Python
Handling of JSON files in Python
Get the script path in Python
Get the desktop path in Python
Get the host name in Python
Wrap (part of) the AtCoder Library in Cython for use in Python
[python] Get the rank of the values in List in ascending / descending order
Get the title and delivery date of Yahoo! News in Python
Get the number of readers of a treatise on Mendeley in Python
Get additional data in LDAP with python
Data input / output in Python (CSV, JSON)
Check the behavior of destructor in Python
Get the column list & data list of CASTable
Summary of various for statements in Python
Get Google Fit API data in Python
The result of installing python in Anaconda
Get Youtube data in Python using Youtube Data API
MongoDB for the first time in Python
The basics of running NoxPlayer in Python
Get a token for conoha in python
Pandas of the beginner, by the beginner, for the beginner [Python]
Get the value of the middle layer of NN
The second night of the loop with for
In search of the fastest FizzBuzz in Python
[Python] Get the character code of the file
Get the EDINET code list in Python
Get rid of DICOM images in Python
Get a capture of the entire web page in Selenium Python VBA
Memo of pixel position operation for image data in Python (numpy, cv2)
Get a datetime instance at any time of the day in Python
Get time series data from k-db.com in Python
CERTIFICATE_VERIFY_FAILED in Python 3.6, the official installer for macOS
Get the contents of git diff from python
[Python] Get the files in a folder with Python
Get the weather in Osaka via WebAPI (python)
Use something other than a <br> string for the <br> dict key in Python
The story of low learning costs for Python
[Python] Sort the list of pathlib.Path in natural sort
Just add the python array to the json data
[Python] Get / edit the scale label of the figure
[Python] Get the main topics of Yahoo News