1

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.

1 Answer 1

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.