Title: How to get length of list from a json reponse from API request in python?
Tags: python,json,python-3.x,list,dictionary

Question: I'm trying to get json response from API get method and get a length of a list names items in the response.
This the API json reponse
{
    "identifier": "id",
    "items": [
        {
            "deployPending": "NONE",
            "networkResource": {
                "type": "ManagedNetworkElement",
                "id": 4424479,
                "longType": "com.cisco.xmp.model.foundation.encapsulatedFunctionality.ManagedNetworkElement",
                "url": "../../ManagedNetworkElement/4424479"
            },
            "bridgeGroupName": "Provisioned",
            "networkResourceUrl": "../../EthMaintenanceEntityGroupSettings/4476198/related/networkResource",
            "shortMaintenanceName": "18",
            "cfmServiceType": "IEEE",
            "megId": "EVC18",
            "shortMaintenanceNameType": "UNSIGNED_INT16",
            "bridgeDomainName": "dppevplan",
            "isInterfaceStatusTlvIncluded": true,
            "isPortStatusTlvIncluded": true,
            "maxMEPs": 0,
            "peerMepAgingPeriod": 0,
            "transmissionPeriod": "_1_SEC",
            "ethMDUrl": "../../EthMaintenanceEntityGroupSettings/4476198/related/ethMD",
            "ethMD": {
                "type": "EthMaintenanceDomainSettings",
                "id": 4478604,
                "longType": "com.cisco.xmp.model.managed.standardTechnologies.cfm.common.EthMaintenanceDomainSettings",
                "url": "../../EthMaintenanceDomainSettings/4478604"
            },
            "rootMEPUrl": "../../EthMaintenanceEntityGroupSettings/4476198/related/rootMEP",
            "rootMEP": {
                "rootMEP": [
                    {
                        "type": "EoamPmMep",
                        "id": 4485928,
                        "longType": "com.cisco.xmp.model.managed.standardTechnologies.pm.EoamPmMep",
                        "url": "../../EoamPmMep/4485928"
                    }
                ]
            },
            "name": "dppevplan",
            "displayName": "8dfb4029[EVC18,4420459_10.104.120.130]",
            "id": 4476198,
            "uuid": "7043487a-6d6b-4a89-998b-3a58dfea7978"
        },
        {
            "deployPending": "NONE",
            "networkResource": {
                "type": "ManagedNetworkElement",
                "id": 4424479,
                "longType": "com.cisco.xmp.model.foundation.encapsulatedFunctionality.ManagedNetworkElement",
                "url": "../../ManagedNetworkElement/4424479"
            },
            "networkResourceUrl": "../../EthMaintenanceEntityGroupSettings/4476196/related/networkResource",
            "shortMaintenanceName": "7",
            "cfmServiceType": "IEEE",
            "megId": "EVC7",
            "shortMaintenanceNameType": "UNSIGNED_INT16",
            "crossConnectGroupName": "Provisioned",
            "isInterfaceStatusTlvIncluded": true,
            "isPortStatusTlvIncluded": true,
            "maxMEPs": 0,
            "p2pName": "test-y1731",
            "peerMepAgingPeriod": 0,
            "transmissionPeriod": "_1_SEC",
            "ethMDUrl": "../../EthMaintenanceEntityGroupSettings/4476196/related/ethMD",
            "ethMD": {
                "type": "EthMaintenanceDomainSettings",
                "id": 4478604,
                "longType": "com.cisco.xmp.model.managed.standardTechnologies.cfm.common.EthMaintenanceDomainSettings",
                "url": "../../EthMaintenanceDomainSettings/4478604"
            },
            "rootMEPUrl": "../../EthMaintenanceEntityGroupSettings/4476196/related/rootMEP",
            "rootMEP": {
                "rootMEP": [
                    {
                        "type": "EoamPmMep",
                        "id": 4485927,
                        "longType": "com.cisco.xmp.model.managed.standardTechnologies.pm.EoamPmMep",
                        "url": "../../EoamPmMep/4485927"
                    }
                ]
            },
            "name": "test-y1731",
            "displayName": "8dfb4029[EVC7,4420459_10.104.120.130]",
            "id": 4476196,
            "uuid": "b4d7623b-3392-4943-8762-51f28c0bdf8f"
        },
        {
            "deployPending": "NONE",
            "networkResource": {
                "type": "ManagedNetworkElement",
                "id": 4424479,
                "longType": "com.cisco.xmp.model.foundation.encapsulatedFunctionality.ManagedNetworkElement",
                "url": "../../ManagedNetworkElement/4424479"
            },
            "bridgeGroupName": "Provisioned",
            "networkResourceUrl": "../../EthMaintenanceEntityGroupSettings/4476197/related/networkResource",
            "shortMaintenanceName": "6",
            "cfmServiceType": "IEEE",
            "megId": "EVC6",
            "shortMaintenanceNameType": "UNSIGNED_INT16",
            "bridgeDomainName": "evplan",
            "isInterfaceStatusTlvIncluded": true,
            "isPortStatusTlvIncluded": true,
            "maxMEPs": 0,
            "peerMepAgingPeriod": 0,
            "transmissionPeriod": "_1_SEC",
            "ethMDUrl": "../../EthMaintenanceEntityGroupSettings/4476197/related/ethMD",
            "ethMD": {
                "type": "EthMaintenanceDomainSettings",
                "id": 4478604,
                "longType": "com.cisco.xmp.model.managed.standardTechnologies.cfm.common.EthMaintenanceDomainSettings",
                "url": "../../EthMaintenanceDomainSettings/4478604"
            },
            "rootMEPUrl": "../../EthMaintenanceEntityGroupSettings/4476197/related/rootMEP",
            "rootMEP": {
                "rootMEP": [
                    {
                        "type": "EoamPmMep",
                        "id": 4485926,
                        "longType": "com.cisco.xmp.model.managed.standardTechnologies.pm.EoamPmMep",
                        "url": "../../EoamPmMep/4485926"
                    }
                ]
            },
            "name": "evplan",
            "displayName": "8dfb4029[EVC6,4420459_10.104.120.130]",
            "id": 4476197,
            "uuid": "8b79491a-80b1-4293-94c5-d62406c9ad33"
        },
        {
            "deployPending": "NONE",
            "networkResource": {
                "type": "ManagedNetworkElement",
                "id": 4424479,
                "longType": "com.cisco.xmp.model.foundation.encapsulatedFunctionality.ManagedNetworkElement",
                "url": "../../ManagedNetworkElement/4424479"
            },
            "networkResourceUrl": "../../EthMaintenanceEntityGroupSettings/4476199/related/networkResource",
            "shortMaintenanceName": "24",
            "cfmServiceType": "IEEE",
            "megId": "EVC24",
            "shortMaintenanceNameType": "UNSIGNED_INT16",
            "crossConnectGroupName": "Provisioned",
            "isInterfaceStatusTlvIncluded": true,
            "isPortStatusTlvIncluded": true,
            "maxMEPs": 0,
            "p2pName": "dpp_test_evpl",
            "peerMepAgingPeriod": 0,
            "transmissionPeriod": "_1_SEC",
            "ethMDUrl": "../../EthMaintenanceEntityGroupSettings/4476199/related/ethMD",
            "ethMD": {
                "type": "EthMaintenanceDomainSettings",
                "id": 4478604,
                "longType": "com.cisco.xmp.model.managed.standardTechnologies.cfm.common.EthMaintenanceDomainSettings",
                "url": "../../EthMaintenanceDomainSettings/4478604"
            },
            "rootMEPUrl": "../../EthMaintenanceEntityGroupSettings/4476199/related/rootMEP",
            "rootMEP": {
                "rootMEP": [
                    {
                        "type": "EoamPmMep",
                        "id": 4485921,
                        "longType": "com.cisco.xmp.model.managed.standardTechnologies.pm.EoamPmMep",
                        "url": "../../EoamPmMep/4485921"
                    }
                ]
            },
            "name": "dpp_test_evpl",
            "displayName": "8dfb4029[EVC24,4420459_10.104.120.130]",
            "id": 4476199,
            "uuid": "ae72c328-f97e-4f92-889e-06ee72fe2883"
        },
        {
            "deployPending": "NONE",
            "networkResource": {
                "type": "ManagedNetworkElement",
                "id": 4424479,
                "longType": "com.cisco.xmp.model.foundation.encapsulatedFunctionality.ManagedNetworkElement",
                "url": "../../ManagedNetworkElement/4424479"
            },
            "networkResourceUrl": "../../EthMaintenanceEntityGroupSettings/4476194/related/networkResource",
            "shortMaintenanceName": "5",
            "cfmServiceType": "IEEE",
            "megId": "EVC5",
            "shortMaintenanceNameType": "UNSIGNED_INT16",
            "crossConnectGroupName": "Provisioned",
            "isInterfaceStatusTlvIncluded": true,
            "isPortStatusTlvIncluded": true,
            "maxMEPs": 0,
            "p2pName": "EVPL-TEST1",
            "peerMepAgingPeriod": 0,
            "transmissionPeriod": "_1_SEC",
            "ethMDUrl": "../../EthMaintenanceEntityGroupSettings/4476194/related/ethMD",
            "ethMD": {
                "type": "EthMaintenanceDomainSettings",
                "id": 4478604,
                "longType": "com.cisco.xmp.model.managed.standardTechnologies.cfm.common.EthMaintenanceDomainSettings",
                "url": "../../EthMaintenanceDomainSettings/4478604"
            },
            "rootMEPUrl": "../../EthMaintenanceEntityGroupSettings/4476194/related/rootMEP",
            "rootMEP": {
                "rootMEP": [
                    {
                        "type": "EoamPmMep",
                        "id": 4485925,
                        "longType": "com.cisco.xmp.model.managed.standardTechnologies.pm.EoamPmMep",
                        "url": "../../EoamPmMep/4485925"
                    }
                ]
            },
            "name": "EVPL-TEST1",
            "displayName": "8dfb4029[EVC5,4420459_10.104.120.130]",
            "id": 4476194,
            "uuid": "189ce152-056d-4809-b8df-d15eb0545f42"
        },
        {
            "deployPending": "NONE",
            "networkResource": {
                "type": "ManagedNetworkElement",
                "id": 4424479,
                "longType": "com.cisco.xmp.model.foundation.encapsulatedFunctionality.ManagedNetworkElement",
                "url": "../../ManagedNetworkElement/4424479"
            },
            "networkResourceUrl": "../../EthMaintenanceEntityGroupSettings/4476195/related/networkResource",
            "shortMaintenanceName": "4",
            "cfmServiceType": "IEEE",
            "megId": "EVC4",
            "shortMaintenanceNameType": "UNSIGNED_INT16",
            "crossConnectGroupName": "Provisioned",
            "isInterfaceStatusTlvIncluded": true,
            "isPortStatusTlvIncluded": true,
            "maxMEPs": 0,
            "p2pName": "Test-EVPL",
            "peerMepAgingPeriod": 0,
            "transmissionPeriod": "_1_SEC",
            "ethMDUrl": "../../EthMaintenanceEntityGroupSettings/4476195/related/ethMD",
            "ethMD": {
                "type": "EthMaintenanceDomainSettings",
                "id": 4478604,
                "longType": "com.cisco.xmp.model.managed.standardTechnologies.cfm.common.EthMaintenanceDomainSettings",
                "url": "../../EthMaintenanceDomainSettings/4478604"
            },
            "rootMEPUrl": "../../EthMaintenanceEntityGroupSettings/4476195/related/rootMEP",
            "rootMEP": {
                "rootMEP": [
                    {
                        "type": "EoamPmMep",
                        "id": 4485924,
                        "longType": "com.cisco.xmp.model.managed.standardTechnologies.pm.EoamPmMep",
                        "url": "../../EoamPmMep/4485924"
                    }
                ]
            },
            "name": "Test-EVPL",
            "displayName": "8dfb4029[EVC4,4420459_10.104.120.130]",
            "id": 4476195,
            "uuid": "585b1f48-81cb-4b67-b871-acd3d320fc60"
        },
        {
            "deployPending": "NONE",
            "networkResource": {
                "type": "ManagedNetworkElement",
                "id": 4424479,
                "longType": "com.cisco.xmp.model.foundation.encapsulatedFunctionality.ManagedNetworkElement",
                "url": "../../ManagedNetworkElement/4424479"
            },
            "networkResourceUrl": "../../EthMaintenanceEntityGroupSettings/4476192/related/networkResource",
            "shortMaintenanceName": "3",
            "cfmServiceType": "IEEE",
            "megId": "EVC3",
            "shortMaintenanceNameType": "UNSIGNED_INT16",
            "crossConnectGroupName": "Provisioned",
            "isInterfaceStatusTlvIncluded": true,
            "isPortStatusTlvIncluded": true,
            "maxMEPs": 0,
            "p2pName": "EVPL-130-58-Y1731",
            "peerMepAgingPeriod": 0,
            "transmissionPeriod": "_1_SEC",
            "ethMDUrl": "../../EthMaintenanceEntityGroupSettings/4476192/related/ethMD",
            "ethMD": {
                "type": "EthMaintenanceDomainSettings",
                "id": 4478604,
                "longType": "com.cisco.xmp.model.managed.standardTechnologies.cfm.common.EthMaintenanceDomainSettings",
                "url": "../../EthMaintenanceDomainSettings/4478604"
            },
            "rootMEPUrl": "../../EthMaintenanceEntityGroupSettings/4476192/related/rootMEP",
            "rootMEP": {
                "rootMEP": [
                    {
                        "type": "EoamPmMep",
                        "id": 4485923,
                        "longType": "com.cisco.xmp.model.managed.standardTechnologies.pm.EoamPmMep",
                        "url": "../../EoamPmMep/4485923"
                    }
                ]
            },
            "name": "EVPL-130-58-Y1731",
            "displayName": "8dfb4029[EVC3,4420459_10.104.120.130]",
            "id": 4476192,
            "uuid": "d377a368-b7dd-4e72-91f1-0bc16e7203cb"
        },
        {
            "deployPending": "NONE",
            "networkResource": {
                "type": "ManagedNetworkElement",
                "id": 4424479,
                "longType": "com.cisco.xmp.model.foundation.encapsulatedFunctionality.ManagedNetworkElement",
                "url": "../../ManagedNetworkElement/4424479"
            },
            "networkResourceUrl": "../../EthMaintenanceEntityGroupSettings/4476193/related/networkResource",
            "shortMaintenanceName": "2",
            "cfmServiceType": "IEEE",
            "megId": "EVC2",
            "shortMaintenanceNameType": "UNSIGNED_INT16",
            "crossConnectGroupName": "Provisioned",
            "isInterfaceStatusTlvIncluded": true,
            "isPortStatusTlvIncluded": true,
            "maxMEPs": 0,
            "p2pName": "evpl-130-70-1",
            "peerMepAgingPeriod": 0,
            "transmissionPeriod": "_1_SEC",
            "ethMDUrl": "../../EthMaintenanceEntityGroupSettings/4476193/related/ethMD",
            "ethMD": {
                "type": "EthMaintenanceDomainSettings",
                "id": 4478604,
                "longType": "com.cisco.xmp.model.managed.standardTechnologies.cfm.common.EthMaintenanceDomainSettings",
                "url": "../../EthMaintenanceDomainSettings/4478604"
            },
            "rootMEPUrl": "../../EthMaintenanceEntityGroupSettings/4476193/related/rootMEP",
            "rootMEP": {
                "rootMEP": [
                    {
                        "type": "EoamPmMep",
                        "id": 4485922,
                        "longType": "com.cisco.xmp.model.managed.standardTechnologies.pm.EoamPmMep",
                        "url": "../../EoamPmMep/4485922"
                    }
                ]
            },
            "name": "evpl-130-70-1",
            "displayName": "8dfb4029[EVC2,4420459_10.104.120.130]",
            "id": 4476193,
            "uuid": "778c18a0-9a51-47fe-998c-a13b11412c34"
        },
        {
            "deployPending": "NONE",
            "networkResource": {
                "type": "ManagedNetworkElement",
                "id": 4424479,
                "longType": "com.cisco.xmp.model.foundation.encapsulatedFunctionality.ManagedNetworkElement",
                "url": "../../ManagedNetworkElement/4424479"
            },
            "networkResourceUrl": "../../EthMaintenanceEntityGroupSettings/4476191/related/networkResource",
            "shortMaintenanceName": "1",
            "cfmServiceType": "IEEE",
            "megId": "EVC1",
            "shortMaintenanceNameType": "UNSIGNED_INT16",
            "crossConnectGroupName": "EVPN-Provisioned",
            "isInterfaceStatusTlvIncluded": true,
            "isPortStatusTlvIncluded": true,
            "maxMEPs": 0,
            "p2pName": "l2vpn-evpn-130-70-1",
            "peerMepAgingPeriod": 0,
            "transmissionPeriod": "_1_SEC",
            "ethMDUrl": "../../EthMaintenanceEntityGroupSettings/4476191/related/ethMD",
            "ethMD": {
                "type": "EthMaintenanceDomainSettings",
                "id": 4478604,
                "longType": "com.cisco.xmp.model.managed.standardTechnologies.cfm.common.EthMaintenanceDomainSettings",
                "url": "../../EthMaintenanceDomainSettings/4478604"
            },
            "name": "l2vpn-evpn-130-70-1",
            "displayName": "8dfb4029[EVC1,4420459_10.104.120.130]",
            "id": 4476191,
            "uuid": "4cdf848c-71b8-40b1-a134-01b21bef7f2c"
        }
    ],
    "status": {
        "statusCode": 0,
        "statusMessage": "Get operation is successful",
        "hideDialog": true
    }
}

Here items is a list. And I want to get the length of the list
I have tried with following code
            response = self.rest_oper_obj.get_operation(headers=headers_updated, url=self.base_url +
                                                                                     self.URL_getAllCFM.replace
                                                                                     ("__evcId__", str(evcId)),
                                                        expected_return_code=[200], flag=True)
            logger.info("Response Body: {}".format(response.text))
            logger.info("Response code: {}".format(response.status_code))
            if response.status_code == 200:
                if "success" in response.text:
                    if "items" in response.text:
                        evc_data = response.json()
                        evc_list = evc_data('items') #getting error in this line
                        evc_count = len(evc_list)
                        print(evc_count)

But I'm not able to print the value, I'm getting error 'dict' object is not callable

Answer: Per my comment on your question, you should replace evc_data('items') with evc_data['items']. The former is viewed as a function call while the latter is a dict access (in this instance).
Remember to accept an answer if it satisfied your question.