<p>I figured this out myself. I needed to use PHP array syntax.</p>

<p>In answer to my own question, the updated code for a nested object would be:</p>

<pre><code>...

return [
    "type" =&gt; "Feature",
    "geometry" =&gt; array("type" =&gt; "Point", "coordinates" =&gt; [125.6, 10.1]),
    "properties" =&gt; array("name" =&gt; "Dinagat Islands")
];

...
</code></pre>

<p>Hope this helps someone else as it wasn't immediately apparent to me.</p>

CC BY-SA 3.0
2016-03-18T18:41:02.117Z
2016-03-18T23:49:42.567Z
2016-03-18T23:49:42.567Z
gethyn1
<p>I'm trying to create a GeoJSON feed using the Element API plugin but having difficulty creating the nested structure required for the JSON object:</p>

<pre><code>{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [125.6, 10.1]
  },
  "properties": {
    "name": "Dinagat Islands"
  }
}
</code></pre>

<p>I can get a flat json structure using:</p>

<pre><code>...

return [
    "type" =&gt; "Feature",
    "geometry" =&gt; "",
    "properties" =&gt; ""
];

...
</code></pre>

<p>My question is, how would I update the above code to create the nested json objects for <code>geometry</code> and <code>properties</code>?</p>

<p>Thanks. G.</p>

<plugin-elementapi>
Nested objects for geoJSON using Element API
# Nested objects for geoJSON using Element API

(Asked by: username_0 on 2016-03-18)

I'm trying to create a GeoJSON feed using the Element API plugin but having difficulty creating the nested structure required for the JSON object:
{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [125.6, 10.1]
  },
  "properties": {
    "name": "Dinagat Islands"
  }
}

I can get a flat json structure using:
...

return [
    "type" => "Feature",
    "geometry" => "",
    "properties" => ""
];

...

My question is, how would I update the above code to create the nested json objects for geometry and properties?
Thanks. G.

**Tags:** plugin-elementapi

---

## 1 answers

### Answer by username_0 on 2016-03-18. Score: 3 | Accepted answer

I figured this out myself. I needed to use PHP array syntax.
In answer to my own question, the updated code for a nested object would be:
...

return [
    "type" => "Feature",
    "geometry" => array("type" => "Point", "coordinates" => [125.6, 10.1]),
    "properties" => array("name" => "Dinagat Islands")
];

...

Hope this helps someone else as it wasn't immediately apparent to me.


---

