<p>Though I don't know the Element API, have you tried</p>

<pre><code>    return $allOverChallenges;
</code></pre>

<p>instead of</p>

<pre><code>    return [
        $allOverChallenges
    ];
</code></pre>

<p>It looks like you are simply adding these brackets (Array) on the return.</p>

CC BY-SA 3.0
2017-08-15T10:09:32.133Z
Well, that sure was easy and obvious, wasn't it? It works, thank you! I feel really dumb now :)
justussimon91
CC BY-SA 3.0
2017-08-15T09:57:48.693Z
2017-08-15T09:57:48.693Z
Matthias Redl-Mann
<p>We're currently having an Android-App access some of the entries of our Craft-based website. We are currently still using a self built API, and for easier creation of new API-Calls we are trying to migrate over to Pixel &amp; Tonic's Element API plugin.</p>

<p>The entries (or the blocks of a Matrix-field of that entry, to be more precise) are accessed like so:</p>

<pre><code>'api/alloverlist' =&gt; function() { // GET ALLOVER-CHALLENGES
        return [
            'elementType' =&gt; ElementType::Entry,
            'criteria' =&gt; [
                'section' =&gt; 'challenges',
                ],
            'paginate' =&gt; false,
            'first' =&gt; true,
            'transformer' =&gt; function(EntryModel $entry){

                $allOverChallenges = [];
                foreach ($entry-&gt;allOverChallenge as $challenge){
                    $allOverChallenges[] = [
                        'elementId' =&gt; $challenge-&gt;id,
                        'field_allOverChallenge_allOverName' =&gt; $challenge-&gt;allOverName,
                    ];
                }

                return [
                    $allOverChallenges
                ];
            },
        ];
    },
</code></pre>

<p>The returned JSON-String has the following appearance:</p>

<pre><code>[
[
    {
        "elementId": "1298",
        "field_allOverChallenge_allOverName": "Dein schönster Sonnenaufgang"
    },
    {
        "elementId": "1310",
        "field_allOverChallenge_allOverName": "AllOverChallenge2"
    },
    {
        "elementId": "1318",
        "field_allOverChallenge_allOverName": "Allover Challenge 3"
    }
]
]
</code></pre>

<p>However, the Android-App accepts the JSON-String just with single square-brackets, like so:</p>

<pre><code>[
   {
     "key":"value",
      ...
   },

   {
     "key":"value",
      ...
   }
]
</code></pre>

<p>For the sake of not having to change the existing Android-App, is it somehow possible to remove the additional square brackets? </p>

<p>Thanks.</p>

<plugin-elementapi><json><format>
Element API: Remove additional set of square brackets from JSON-String
# Element API: Remove additional set of square brackets from JSON-String

(Asked by: username_0 on 2017-08-15)

We're currently having an Android-App access some of the entries of our Craft-based website. We are currently still using a self built API, and for easier creation of new API-Calls we are trying to migrate over to Pixel & Tonic's Element API plugin.
The entries (or the blocks of a Matrix-field of that entry, to be more precise) are accessed like so:
'api/alloverlist' => function() { // GET ALLOVER-CHALLENGES
        return [
            'elementType' => ElementType::Entry,
            'criteria' => [
                'section' => 'challenges',
                ],
            'paginate' => false,
            'first' => true,
            'transformer' => function(EntryModel $entry){

                $allOverChallenges = [];
                foreach ($entry->allOverChallenge as $challenge){
                    $allOverChallenges[] = [
                        'elementId' => $challenge->id,
                        'field_allOverChallenge_allOverName' => $challenge->allOverName,
                    ];
                }

                return [
                    $allOverChallenges
                ];
            },
        ];
    },

The returned JSON-String has the following appearance:
[
[
    {
        "elementId": "1298",
        "field_allOverChallenge_allOverName": "Dein schönster Sonnenaufgang"
    },
    {
        "elementId": "1310",
        "field_allOverChallenge_allOverName": "AllOverChallenge2"
    },
    {
        "elementId": "1318",
        "field_allOverChallenge_allOverName": "Allover Challenge 3"
    }
]
]

However, the Android-App accepts the JSON-String just with single square-brackets, like so:
[
   {
     "key":"value",
      ...
   },

   {
     "key":"value",
      ...
   }
]

For the sake of not having to change the existing Android-App, is it somehow possible to remove the additional square brackets? 
Thanks.

**Tags:** plugin-elementapi, json, format


---

## 1 answers

### Answer by username_1 on 2017-08-15. Score: 3 | Accepted answer

Though I don't know the Element API, have you tried
    return $allOverChallenges;

instead of
    return [
        $allOverChallenges
    ];

It looks like you are simply adding these brackets (Array) on the return.

> **Comments:**
> **username_0**: Well, that sure was easy and obvious, wasn't it? It works, thank you! I feel really dumb now :)  

---

