<p>I would approach this by splitting up the work into two tasks:</p>

<ol>
<li>Import the categories and their parent/child relationships first</li>
<li>Import the entries with a flat listing of categories (just the cities is okay).</li>
</ol>

<p>The structure of the JSON for importing the categories would be something like this:</p>

<pre><code>[
  {
    "state": "Florida",
    "city": "Key West"
  },
  {
    "state": "Florida",
    "city": "Orlando"
  },
  {
    "state": "Florida",
    "city": "Jackonsville"
  },
  {
    "state": "Florida",
    "city": "Miami"
  },
  {
    "state": "Florida",
    "city": "Tampa"
  },
  {
    "state": "Texas",
    "city": "Austin"
  },
  {
    "state": "Texas",
    "city": "Dallas"
  },
  {
    "state": "Texas",
    "city": "San Antonio"
  }
]
</code></pre>

<p>I know this is redundant but it works better with how Feed Me loops over the category elements and creates the category if it doesn't exist and then assigns the parent if (and creates it if it doesn't exist).</p>

<p>You want the mapping to look something like this:</p>

<p><a href="https://i.sstatic.net/rsp3g.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/rsp3g.png" alt="mapping fields in Feed Me"></a></p>

<p>When you go to import your entries you only need to include a flat listing of the category titles (cities) and then they'll be mapped to parent state.</p>

CC BY-SA 4.0
2020-01-14T02:06:37.413Z
Here's a video with the same approach: https://craftquest.io/lessons/import-nested-categories-from-json-with-feed-me
CraftQuest
CC BY-SA 4.0
2020-02-25T18:23:55.053Z
thanks a lot for your answer and video! But what can I do to assign the right city if I have cities with the same names in different states?
Dmitry Borovkov
CC BY-SA 4.0
2020-01-12T21:23:43.673Z
2020-01-12T21:23:43.673Z
CraftQuest
<p>I'm trying to import nested categories. My JSON is like:</p>

<pre><code>[{"title":"Title""location":[{"Florida":["Key West"]}]}]
</code></pre>

<p>I want to be created "Florida" category and nested child "Key West"
But plugin offers me to import that like this:
<a href="https://d.pr/free/i/NvgGOm" rel="nofollow noreferrer">https://d.pr/free/i/NvgGOm</a></p>

<p>Only "Key West" category will be created.</p>

<p>Is it possible to import nested categories? What is the right JSON structure for that?</p>

<p>Additional info:</p>

<ul>
<li>Plugin version: 4.1.2</li>
<li>Craft version:3.3.18.4</li>
</ul>

<categories><plugin-feedme>
Create nested categories with Feed Me plugin
# Create nested categories with Feed Me plugin

(Asked by: username_0 on 2019-12-28)

I'm trying to import nested categories. My JSON is like:
[{"title":"Title""location":[{"Florida":["Key West"]}]}]

I want to be created "Florida" category and nested child "Key West"
But plugin offers me to import that like this:
https://d.pr/free/i/NvgGOm
Only "Key West" category will be created.
Is it possible to import nested categories? What is the right JSON structure for that?
Additional info:

Plugin version: 4.1.2
Craft version:3.3.18.4

**Tags:** categories, plugin-feedme

---

## 1 answers

### Answer by username_1 on 2020-01-12. Score: 1 | Accepted answer

I would approach this by splitting up the work into two tasks:

Import the categories and their parent/child relationships first
Import the entries with a flat listing of categories (just the cities is okay).

The structure of the JSON for importing the categories would be something like this:
[
  {
    "state": "Florida",
    "city": "Key West"
  },
  {
    "state": "Florida",
    "city": "Orlando"
  },
  {
    "state": "Florida",
    "city": "Jackonsville"
  },
  {
    "state": "Florida",
    "city": "Miami"
  },
  {
    "state": "Florida",
    "city": "Tampa"
  },
  {
    "state": "Texas",
    "city": "Austin"
  },
  {
    "state": "Texas",
    "city": "Dallas"
  },
  {
    "state": "Texas",
    "city": "San Antonio"
  }
]

I know this is redundant but it works better with how Feed Me loops over the category elements and creates the category if it doesn't exist and then assigns the parent if (and creates it if it doesn't exist).
You want the mapping to look something like this:

When you go to import your entries you only need to include a flat listing of the category titles (cities) and then they'll be mapped to parent state.

> **Comments:**
> **username_1**: Here's a video with the same approach: https://craftquest.io/lessons/import-nested-categories-from-json-with-feed-me  
> **username_0**: thanks a lot for your answer and video! But what can I do to assign the right city if I have cities with the same names in different states?  

---

