I have a JSON string as below
typ_json="{'FromPort': 80, 'IpProtocol': 'tcp', 'IpRanges': [{'CidrIp': '0.0.0.0/0'}], 'Ipv6Ranges': [{'CidrIpv6': '::/0'}], 'PrefixListIds': [], 'ToPort': 80, 'UserIdGroupPairs': []}"
I want to access FromPort and ToPort Values.
I have tried print(typ_json['FromPort'])
But I get the error:
TypeError: list indices must be integers or slices, not str
typ_json.get(key)instead of directly accessing the key, as it might not exist.str.TypeError: list indices must be integers or slices, not strsuggests it is alist, but what you showed is astr