How to Parse Unstructured Input Text into an International Formatted Address with JavaScript

Cloudmersive
2 min readAug 5, 2022

--

When it comes to saving structured contact information like addresses, correct formatting is key — or referencing that data becomes a messy task. While it’s certainly easiest to receive address data through structured forms with specific input parameters, it isn’t always possible, and that’s where machine learning/NLP can play a helpful role. Our Unstructured Address Parser API uses machine learning/NLP to turn unstructured address strings into correctly formatted international address. All available information in the original unstructured string will be classified & organized into categories like building, street, postal code, city & more and returned as individual text strings labeling each value.

It’s free to use this API (with zero commitments) — just register a free account on our website, and include your API key where indicated in the code documentation below. To help you get started, I’ll demonstrate how you can structure your API call using two different methods in JavaScript.

The first method I’ll demonstrate involves using the built-in XHR feature in JavaScript. All you need to do is copy & paste the below code:

var data = JSON.stringify({
"AddressString": "<string>",
"CapitalizationMode": "<string>"
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://api.cloudmersive.com/validate/address/parse");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Apikey", "YOUR-API-KEY-HERE");
xhr.send(data);

The second method starts by installing the jQuery library. You can do that by first running the following command:

bower install jquery

Then you can call the function:

var settings = {
"url": "https://api.cloudmersive.com/validate/address/parse",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/json",
"Apikey": "YOUR-API-KEY-HERE"
},
"data": JSON.stringify({
"AddressString": "<string>",
"CapitalizationMode": "<string>"
}),
};
$.ajax(settings).done(function (response) {
console.log(response);
});

It’s just that simple — no more code contributions required.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet