# Adding to GeoJSON Properties

**URL:** <https://talk.observablehq.com/t/adding-to-geojson-properties/7271>\
**Category:** Help\
**Created:** [November 11, 2022, 5:58pm UTC](https://talk.observablehq.com/t/adding-to-geojson-properties/7271 "2022-11-11T17:58:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zachbogart](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/zachbogart/32/8597_2.png) [@zachbogart](https://talk.observablehq.com/u/zachbogart)\
**Post date:** [November 11, 2022, 5:58pm UTC](https://talk.observablehq.com/t/adding-to-geojson-properties/7271/1 "2022-11-11T17:58:51Z")

</div>

I have a dataset and the IDs that connect to GeoJSON by state. I’m wondering how I can merge the two together so I have a GeoJSON that now includes more properties for each feature. Basically, I want to expand the stateShapes so that it has properties for each of the features, using my dataset to join against, but I’m having trouble figuring out how I could join it up. How can I wrangle my data so that each feature joins by their id and now has more properties?

[Notebook](https://observablehq.com/d/6293726d8a4068e6)

Always learning,  
Zach

---

<div class="post-metadata">

**Author:** ![Fil](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/fil/32/207_2.png) [@Fil](https://talk.observablehq.com/u/Fil)\
**Post date:** [November 11, 2022, 7:21pm UTC](https://talk.observablehq.com/t/adding-to-geojson-properties/7271/2 "2022-11-11T19:21:46Z")

</div>

I’ve sent you a suggestion, using a Map to index the data, then reading the values from that map for each of the features.

---

<div class="post-metadata">

**Author:** ![zachbogart](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/zachbogart/32/8597_2.png) [@zachbogart](https://talk.observablehq.com/u/zachbogart)\
**Post date:** [November 11, 2022, 7:35pm UTC](https://talk.observablehq.com/t/adding-to-geojson-properties/7271/3 "2022-11-11T19:35:52Z")

</div>

Cool that’s great! And I could have the Map index to multiple values, like if I wanted to copy over the state name as well, plus other data?

---

<div class="post-metadata">

**Author:** ![zachbogart](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/zachbogart/32/8597_2.png) [@zachbogart](https://talk.observablehq.com/u/zachbogart)\
**Post date:** [November 11, 2022, 7:49pm UTC](https://talk.observablehq.com/t/adding-to-geojson-properties/7271/4 "2022-11-11T19:49:22Z")

</div>

I basically want to join by “id”, but put all of the values in the properties field, extending it.

---

<div class="post-metadata">

**Author:** ![aaronkyle](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/aaronkyle/32/8106_2.png) [@aaronkyle](https://talk.observablehq.com/u/aaronkyle)\
**Post date:** [November 12, 2022, 1:53am UTC](https://talk.observablehq.com/t/adding-to-geojson-properties/7271/5 "2022-11-12T01:53:56Z")

</div>

Thank you for this discussion. @Fil - I see that the new data is nested under a field with that name. I have been wondering if it’s possible to accomplish this without nesting… For example, in this case matching state name to state name, then just writing in the additional attributes at that same property level?

---

<div class="post-metadata">

**Author:** ![Fil](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/fil/32/207_2.png) [@Fil](https://talk.observablehq.com/u/Fil)\
**Post date:** [November 12, 2022, 8:10am UTC](https://talk.observablehq.com/t/adding-to-geojson-properties/7271/6 "2022-11-12T08:10:08Z")

</div>

yes, exactly. With the new index you could do a merge between the existing and the new properties, like so:

```auto
f.properties= ({
  ...f.properties,
  ...index1.get(f.properties.name)
});

```

You could also use `d3.index(data, d => d.name)` as a shorthand for `new Map(data, d => [d.name, d])`

---

<div class="post-metadata">

**Author:** ![aaronkyle](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/aaronkyle/32/8106_2.png) [@aaronkyle](https://talk.observablehq.com/u/aaronkyle)\
**Post date:** [November 12, 2022, 2:06pm UTC](https://talk.observablehq.com/t/adding-to-geojson-properties/7271/7 "2022-11-12T14:06:03Z")

</div>

Thanks Fil and Zach!  
I re-read Zach’s notebook and Fil’s tips here, but I am still a bit confused about why things are working like they are. I forked Zach’s notebook and added a few comments/questions… in case you have another few moments to help? \<3

> **[Adding to GeoJSON Properties](https://observablehq.com/d/5a36289ce6535c89)**
>
> Forum Discussion I wish to merge two datasets, the first is one I import; the next is one I have on file... I would like to join \`file)data\` to \`stateShapes\` so each feature has the info under \`properties\` (not nested): Let's create a new index:...

Thank you for this opportunity to learn!
