N
N
Nodir Malikov2021-01-25 19:53:44
Python
Nodir Malikov, 2021-01-25 19:53:44

How to output a specific array to json in python?

There are several such arrays like this one:

spoiler
{
    "accounts": [
        {
            "balance": "0.0000",
            "balance_limit": "0.0000",
            "currency": "UZS",
            "id": "5f9b5b88bc624303b27a649683046270",
            "type": "current"
        }
    ],
    "car": {
        "amenities": [],
        "brand": "Daewoo",
        "callsign": "640",
        "category": [
            "econom",
            "comfort",
            "business",
            "start",
            "express"
        ],
        "color": "Бежевый",
        "id": "339fd56291cc4bd0b427978faf5319b0",
        "model": "Matiz",
        "normalized_number": "01P475WA",
        "number": "01P475WA",
        "status": "working",
        "year": 2015
    },
    "current_status": {
        "status": "offline"
    },
    "driver_profile": {
        "created_date": "2018-04-12T14:45:35.337+0000",
        "driver_license": {
            "country": "uzb",
            "expiration_date": "2022-08-15T00:00:00+0000",
            "issue_date": "2014-05-14T00:00:00+0000",
            "normalized_number": "AAC1234575",
            "number": "AAC1234575"
        },
        "first_name": "Равшанбек",
        "hire_date": "2018-04-12T00:00:00+0000",
        "id": "5f9b5b88bc624303b27a649683046270",
        "last_name": "Баратов",
        "middle_name": "Илхом угли",
        "modified_date": "2020-10-15T05:22:26.493+0000",
        "park_id": "9e34e3e8188542f693f75f0b978afd0c",
        "phones": [
            "+998933757757"
        ],
        "work_rule_id": "e26a3cf21acfe01198d50030487e046b",
        "work_status": "working"
    }
}



How can one find a value from it and output the entire array where it is in Python?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antosha Styazhkin, 2021-01-25
@desulaid

Do you mean something similar?

array = {
    "accounts": [
        {
            "balance": "0.0000",
            "balance_limit": "0.0000",
            "currency": "UZS",
            "id": "5f9b5b88bc624303b27a649683046270",
            "type": "current"
        }
    ],
    "car": {
        "amenities": [],
        "brand": "Daewoo",
        "callsign": "640",
        "category": [
            "econom",
            "comfort",
            "business",
            "start",
            "express"
        ],
        "color": "Бежевый",
        "id": "339fd56291cc4bd0b427978faf5319b0",
        "model": "Matiz",
        "normalized_number": "01P475WA",
        "number": "01P475WA",
        "status": "working",
        "year": 2015
    },
    "current_status": {
        "status": "offline"
    },
    "driver_profile": {
        "created_date": "2018-04-12T14:45:35.337+0000",
        "driver_license": {
            "country": "uzb",
            "expiration_date": "2022-08-15T00:00:00+0000",
            "issue_date": "2014-05-14T00:00:00+0000",
            "normalized_number": "AAC1234575",
            "number": "AAC1234575"
        },
        "first_name": "Равшанбек",
        "hire_date": "2018-04-12T00:00:00+0000",
        "id": "5f9b5b88bc624303b27a649683046270",
        "last_name": "Баратов",
        "middle_name": "Илхом угли",
        "modified_date": "2020-10-15T05:22:26.493+0000",
        "park_id": "9e34e3e8188542f693f75f0b978afd0c",
        "phones": [
            "+998933757757"
        ],
        "work_rule_id": "e26a3cf21acfe01198d50030487e046b",
        "work_status": "working"
    }
}

for key in array['accounts'][0]:
    print(key, '=>', array['accounts'][0][key])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question