简体   繁体   中英

I have a data file in json format. How can I find and print the top 20 eij_max values and the associated pretty_formula? I am using python

Here is part of the data file in json format, containing 1 entry. I need to find the 20 compounds (key:pretty_formula) with the highest eij_max values. I appreciate the help, I apologise if this is a basic question, I am new to all this.

{
    "num_results": 3402,
    "valid_response": true,
    "criteria": "{\"piezo\": {\"$ne\": null}}",
    "properties": "[\"pretty_formula\", \"piezo\", \"eij_max\", \"band_gap\", \"energy\"]",
    "response": [
        {
            "pretty_formula": "KMg(PO3)3",
            "piezo": {
                "eij_max": 0.09337344787836212,
                "piezoelectric_tensor": [
                    [
                        0.0,
                        0.0,
                        0.0,
                        0.0,
                        0.0,
                        0.0660250018229951
                    ],
                    [
                        0.06602500182299509,
                        -0.06602499453211871,
                        0.0,
                        0.0,
                        0.0,
                        0.0
                    ],
                    [
                        0.0,
                        0.0,
                        0.0,
                        0.0,
                        0.0,
                        0.0
                    ]
                ],
                "v_max": [
                    -0.0,
                    1.0,
                    0.0
                ]
            },
            "eij_max": null,
            "band_gap": 4.9474,
            "energy": -193.18215352
        },
        {
            "pretty_formula": "Sr2CuSi2O7",

You can easily do something like this to access the eij_max :

import json 

  
# Opening JSON file 

f = open('data.json',) 

  
# returns JSON object as  
# a dictionary 

data = json.load(f) 

  
# Iterating through the json 
# list 

for i in data['response']['piezo']['eij_max']
    print(i) 

  
# Closing file 
f.close() 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM