Currently I’m using the usaadress python library to parse US addresses https://github.com/datamade/usaddress
Example code
address = '456 Elm St, Someville, NY 54321'
print( usaddress.tag(address))
and the generated results is:
> ({'AddressNumber': '456', 'StreetName': 'Elm', 'StreetNamePostType':
> 'St', 'PlaceName': 'Someville', 'StateName': 'NY', 'ZipCode':
> '54321'}, 'Street Address')
All the JSON values have keys besides "Street Address", is there anyway to assign a key to the "Street Address" value also? It will make parsing the JSON using GSON or Jackson much more simple
>Solution :
It looks like usaddress.tag(address) returns a two-element tuple, where the first part is a dictionary that contains all the address components, and the second part is a simple string that describes what kind of address it is — in this case it is a street address, but other possibilities are a PO box, an intersection, etc.
Capture the output from the function:
address_parts, address_type = usaddress.tag(address)
Then create a new key in the dictionary to save the address type:
address_parts['AddressType'] = address_type