I am new to python. I want to extract the elements of array 'Address' from below json. I am trying to use map to split the elements using
r=<below json>
s=r["Customer"]
y=s.map(lambda x:x.split(","))
But I am getting the error as .....AttributeError: 'str' object has no attribute 'map'
Can you please advise which is the best way to do this.
{ "id": "981",
"Customer":
[
{
"Name": "abc",
"Title": "Mr",
"Gender": "M",
"Address": [
{
"Postcode": "2GF",
"StreetName": "Black Street",
"FlatNo": "123",
}
]
},
{
"Name": "xyz",
"Title": "Mrs",
"Gender": "F",
"Address": [
{
"Postcode": "2CX",
"StreetName": "White Street",
"FlatNo": "123",
}
]
}
]
}
json
module to parse json instead of splitting values out of it manually. – Kevinr
when you are usingr.map()
? – Brendan Martinjson
module first. – CodenameLambda.map
method. Where'd you get that from? – Aran-Feyr
a string or a dict? If it's a string, thens=r["Customer"]
should crash withTypeError: string indices must be integers
. If it's a dict and if the value associated with "Customer" is a list, thens.map
should crash withAttributeError: 'list' object has no attribute 'map'
. In either case, you should not be gettingAttributeError: 'str' object has no attribute 'map'
. Can you provide a minimal reproducible example? – Kevin