# Select Field populated with json suddenly not working

**URL:** <https://forum.getkirby.com/t/select-field-populated-with-json-suddenly-not-working/14701>\
**Category:** Questions\
**Tags:** v2\
**Created:** [June 24, 2019, 4:10pm UTC](https://forum.getkirby.com/t/select-field-populated-with-json-suddenly-not-working/14701 "2019-06-24T16:10:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 24, 2019, 4:10pm UTC](https://forum.getkirby.com/t/select-field-populated-with-json-suddenly-not-working/14701/1 "2019-06-24T16:10:49Z")

</div>

I have a select field that gets its values from a json file created by a route. It’s suddenly stopped working on a site i built a while back. When i load the page the progress bar takes ages to get across. PHP 7.1.

It’s 2.5.12. If i hit the json file directly in the browser, thats working fine, but for some reason the select fields are refusing to read it. The select is empty and it wont let me save the page.

Any idea?

The route looks like this…

```auto
  array(
    'pattern' => 'pagelist.json',
    'action' => function() {
      header('Content-type: application/json; charset=utf-8');
      $pages = site()->index()->visible()->filterBy('template', 'not in', ['error', 'blogarticle']);
      $json = array();

      foreach ($pages as $page) {
          $json[$page->autoid()->value()] = $page->title()->value();

      echo json_encode($json);
    }
  ),

```

And the blue print…

```auto
  cblocklinkurl:
      label: Button One Link
      type: select
      options: url
      width: 1/2
      help: The button link value
      url: pagelist.json

```

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 24, 2019, 4:53pm UTC](https://forum.getkirby.com/t/select-field-populated-with-json-suddenly-not-working/14701/2 "2019-06-24T16:53:53Z")

</div>

I think it’s something to do with the modules plugin. Can any confirm it works alright these days? It is 3 years old after all.

@lukasbestle Is there any reason it wouldnt work on newer PHP versions?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 24, 2019, 5:04pm UTC](https://forum.getkirby.com/t/select-field-populated-with-json-suddenly-not-working/14701/3 "2019-06-24T17:04:25Z")

</div>

There’s a problem with your code, it should be:

```auto
foreach ($pages as $page) {
     $json[$page->autoid()->value()] = $page->title()->value();   
}

echo json_encode($json);

```

i.e. with the echo statement outside the loop.

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 24, 2019, 5:14pm UTC](https://forum.getkirby.com/t/select-field-populated-with-json-suddenly-not-working/14701/4 "2019-06-24T17:14:10Z")

</div>

Ah that was my sloppy atempting at pasting in to the forum i removed a couple of confidential lines. The code in project is ok.

I’ve just noticed it works fine on the staging site (real server, running CentOS) - it just doesnt work locally on Valet for some reason. I need it too tho.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:23pm UTC](https://forum.getkirby.com/t/select-field-populated-with-json-suddenly-not-working/14701/5 "2025-02-06T17:23:12Z")

</div>

Archived on February 6, 2025, 5:23pm UTC


