# Extracting specific parts of an address

**URL:** <https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160>\
**Category:** Ask for Help\
**Created:** [April 4, 2023, 9:31pm UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160 "2023-04-04T21:31:35Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathon\_Kohn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jonathon_kohn/32/8593_2.png) [@Jonathon\_Kohn](https://community.glideapps.com/u/Jonathon_Kohn)\
**Post date:** [April 4, 2023, 9:31pm UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160/1 "2023-04-04T21:31:35Z")

</div>

I’m using the new google integration to auto complete addresses then sending them over to shipstation via webhook. However, shipstation requires individual address fields such as street, city, state, zip, etc…

Is there any way I can extract the required parts of this single complete address column into individual columns? I tried the math column lol [state(address)] ☹

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [April 4, 2023, 9:41pm UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160/2 "2023-04-04T21:41:58Z")

</div>

Is the address in a reliably consistent format? Do you have some fake example addresses that follow the format you currently have? Include any variations (street names vs numbers, addition directional indicators such as 12th St N, any with apartment numbers, etc)

Also, does the street include house number and apt/suite number, or are all of those parts separated out as well?

I’m playing around with some results from ChatGPT, but it can largely depend on the format of the address.

---

<div class="post-metadata">

**Author:** ![Jonathon\_Kohn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jonathon_kohn/32/8593_2.png) [@Jonathon\_Kohn](https://community.glideapps.com/u/Jonathon_Kohn)\
**Post date:** [April 5, 2023, 1:43am UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160/3 "2023-04-05T01:43:59Z")

</div>

The addresses are standard:

123 Street Name Apartment X, City Name, State 55555, USA

Some include a unit/apt #, some follow the example you gave.

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [April 5, 2023, 2:19am UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160/4 "2023-04-05T02:19:36Z")

</div>

Do you always have the country at the end? I wasn’t accounting for that.

The ChatGPT solution wasn’t panning out to my liking, so I started from scratch. This is what I have so far. You can place it into a javascript column and pass the address into the p1 parameter. I’m sure it needs several adjustments, especially if the country is part of the address. Also not really sure how it will handle international addresses.

So the idea is that it will take in an address, split it into individual parts, and then return the result in a pipe delimited format. Then you can take that result and use a split text column to convert it into an array. Then use single value columns to pull out each piece into individual columns.

Let me know what kinds of addresses aren’t working and I’ll try to make adjustments.

```auto
try {

// Split Address into two parts
let address = p1.split(',')[0];
let cityStateZip = p1.split(/,(.*)/s)[1];

// Split address into House and StreetUnit
let houseNumber = address.split(' ')[0].trim();
let streetNameUnitNumber = address.substring(address.split(' ')[0].length).trim();

// Split StreetUnit into Street and Unit
let unitIndex = '';
unitIndex = streetNameUnitNumber.toUpperCase().indexOf(' APT');
if (unitIndex<0) {unitIndex = streetNameUnitNumber.toUpperCase().indexOf(' APARTMENT');}
if (unitIndex<0) {unitIndex = streetNameUnitNumber.toUpperCase().indexOf(' SUITE');}

let streetName = '';
let unitNumber = '';
if (unitIndex>0) {
streetName = streetNameUnitNumber.substring(0, unitIndex).trim();
unitNumber = streetNameUnitNumber.substring(unitIndex+1).trim();
} else {
streetName = streetNameUnitNumber.trim() ;
unitNumber = '';
}

// Split cityStateZip
let city = cityStateZip.split(',')[0].trim();
let state = cityStateZip.split(',')[1].trim();
let zipCode = cityStateZip.split(' ')[cityStateZip.split(' ').length-1].trim();

// Joining the extracted parts in a pipe delimited format
let parts = [houseNumber, streetName, unitNumber, city, state, zipCode];
let splitAddress = parts.join('|').replace(',', '');

return splitAddress;

}
catch(error){
}

```

Another option would be to output the result as JSON, and the each piece of the address can be parsed from the JSON. Just depends on the desired output.

---

<div class="post-metadata">

**Author:** ![gannonatwork](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gannonatwork/32/91717_2.png) [@gannonatwork](https://community.glideapps.com/u/gannonatwork)\
**Post date:** [July 15, 2024, 12:18pm UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160/5 "2024-07-15T12:18:48Z")

</div>

@Jeff_Hager this is a great solution. What if I only want to pull out the City from the address, what edits would I make to this script? I’ve tried editing this myself but my lack of JS skills lead to errors and unintended results. 😆

Any input would be greatly appreciated! Thx

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [July 15, 2024, 1:02pm UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160/6 "2024-07-15T13:02:22Z")

</div>

If the above code works for you and you just wanted only the City, then you would only need to set ‘parts’ to only grab City and nothing else.

```auto
let parts = [city];

```

Just note that this does heavily rely on consistent address formatting and a certain format at that. It’s not a perfect solution.

In fact it may be better to split from back to front instead of front to back if the only thing you want is City. This would simplify the javascript. The question would be what do your addresses look like. Do they always end in City, State, Zip? Similar commas, spaces, etc.?

---

<div class="post-metadata">

**Author:** ![gannonatwork](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gannonatwork/32/91717_2.png) [@gannonatwork](https://community.glideapps.com/u/gannonatwork)\
**Post date:** [July 17, 2024, 9:47am UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160/7 "2024-07-17T09:47:06Z")

</div>

Hi, @Jeff_Hager. Yes, I plan on using Radar to auto-populate the address input on the form I’m building and from my testing the formatting seems consistent:

[Address 01] [Address 02], [City], [State] [Zip] [Country]

The edit you gave me works perfectly (of course!) but I’m also considering just using Split Text to convert the address into an array, using Single Value \> From end to pull out the city, and then remove the stray comma with a Template column. I think this way would avoid any issues in case Radar spits out anything funky…would you agree?

 ![Screenshot 2024-07-17 at 4.45.19 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/e/7ea3444cbaa1e7c3a026b63428c92beb5f2d7528.png)

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [July 17, 2024, 9:48am UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160/8 "2024-07-17T09:48:49Z")

</div>

Why don’t you use a comma as your delimiter?

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [July 17, 2024, 9:49am UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160/9 "2024-07-17T09:49:47Z")

</div>

If you’re using the Radar API, you should be able to extract the City directly with a Query JSON column.

---

<div class="post-metadata">

**Author:** ![gannonatwork](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gannonatwork/32/91717_2.png) [@gannonatwork](https://community.glideapps.com/u/gannonatwork)\
**Post date:** [July 17, 2024, 9:54am UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160/10 "2024-07-17T09:54:07Z")

</div>

Hey @ThinhDinh. Yeah, that is much cleaner and eliminates an extra column. The goal here is to create some in-app filter parameters. My thought is in case the client wants to filter by state, zip, or country in the future, I can just add additional SV columns to accommodate. Am I overthinking?

---

<div class="post-metadata">

**Author:** ![gannonatwork](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gannonatwork/32/91717_2.png) [@gannonatwork](https://community.glideapps.com/u/gannonatwork)\
**Post date:** [July 17, 2024, 9:58am UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160/11 "2024-07-17T09:58:30Z")

</div>

Hi @Darren_Murphy. Appreciate the input. I’ve only tested the Radar output using an installation in someone else’s app; I haven’t set up the API yet so don’t know exactly what my options are yet. Does the query workflow you describe consume updates or is like having Radar convert addresses to long and lat?

The client is on a Maker plan, wants address autopopulate — which will already consume a considerable amount of updates — so trying to limit usage wherever I can.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [July 17, 2024, 10:05am UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160/12 "2024-07-17T10:05:00Z")

</div>

I assume that the address is coming from the API response? Once you have the response, extracting specific parts of it won’t use any additional updates.

I recall that Bob Petitto did a tutorial on address auto-complete shortly after the Radar integration was added. You should check that out.

---

<div class="post-metadata">

**Author:** ![gannonatwork](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gannonatwork/32/91717_2.png) [@gannonatwork](https://community.glideapps.com/u/gannonatwork)\
**Post date:** [July 17, 2024, 10:09am UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160/13 "2024-07-17T10:09:39Z")

</div>

Perfect, I was hoping that was the case. I’ll definitely check out Bob’s video to keep me on track during implementation.

Thx to both you and @ThinhDinh for chiming in on this…much appreciated! 👍

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [July 17, 2024, 10:55am UTC](https://community.glideapps.com/t/extracting-specific-parts-of-an-address/60160/14 "2024-07-17T10:55:18Z")

</div>

Here is that tutorial:

> [@sparkles Glide Integrations (Radar, Pexels, Google Calendar, Gmail/Outlook, Twilio)](https://community.glideapps.com/t/glide-integrations-radar-pexels-google-calendar-gmail-outlook-twilio/59315):
>
> wave Hey fellow Gliders! I’m launching a new series on all the wonderful new integrations that Gliders can add to their Glide apps. Without a single line of code, integrate with dozens of platforms: point_right Integrate OpenAI point_right Send Slack or Discord messages point_right Create PDFs with PDFMonkey or Urlbox First up—compass Forward and Reverse Geocoding with [Radar](https://radar.com)[[Glide: Reusable Actions and Integrations (First up—Radar)] ](https://www.youtube.com/watch?v=99Ohi09i6GU)Listing:play_button Radar: Forward/Revers…
