# Generating json

**URL:** <https://forum.getkirby.com/t/generating-json/12522>\
**Category:** Questions\
**Tags:** v3\
**Created:** [January 28, 2019, 7:34pm UTC](https://forum.getkirby.com/t/generating-json/12522 "2019-01-28T19:34:38Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Perry](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/perry/32/1336_2.png) [@Perry](https://forum.getkirby.com/u/Perry)\
**Post date:** [January 28, 2019, 7:34pm UTC](https://forum.getkirby.com/t/generating-json/12522/1 "2019-01-28T19:34:38Z")

</div>

Hello,

> **[Generating JSON](https://getkirby.com/docs/cookbook/content-representations/generating-json)**
>
> Create a JSON representation of your blog content in Kirby.

I try to recreate the cookbook example.

if I call [https://website.com/programm.json](https://website.com/programm.json) can I then see the json? or do I have fetch it for example: with javascript ?  
because I only see the error page

**structur**

- home
- about
- programm → events.txt
  - event1 → event.txt
  - event2 → event.txt

**template**

```
<?php

$data = $pages->find('programm')->children()->published()->flip();
$json = [];

foreach($data as $article) {

  $json[] = [
    'url' => (string)$article->url(),
    'title' => (string)$article->title(),
    'text' => (string)$article->text(),
    'date' => (string)$article->date()
  ];

}

echo json_encode($json);

```

---

<div class="post-metadata">

**Author:** ![bvdputte](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bvdputte/32/8179_2.png) [@bvdputte](https://forum.getkirby.com/u/bvdputte)\
**Post date:** [January 28, 2019, 7:41pm UTC](https://forum.getkirby.com/t/generating-json/12522/2 "2019-01-28T19:41:20Z")

</div>

Just guessing; but shouldn’t you been using `->listed()` instead of `->published()`?

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [January 28, 2019, 7:55pm UTC](https://forum.getkirby.com/t/generating-json/12522/3 "2019-01-28T19:55:41Z")

</div>

the template file of your is `site/templates/events.json.php`?  
does a `site/templates/events.php` template exist?  
does a blueprint `site/blueprints/pages/events.yml` exist and is valid (page editable in panel)?

---

<div class="post-metadata">

**Author:** ![Perry](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/perry/32/1336_2.png) [@Perry](https://forum.getkirby.com/u/Perry)\
**Post date:** [January 28, 2019, 8:27pm UTC](https://forum.getkirby.com/t/generating-json/12522/4 "2019-01-28T20:27:42Z")

</div>

@bnomei 3\*yes

maybe there is an error in the file names

the name of the dir is “programm”  
the textfiles “events” and “event”

the normal template-name is events.php  
and for the json output events.json.php

what is the right url to see the json output  
[https://website.com/programm.json](https://website.com/programm.json)  
or  
[https://website.com/events.json](https://website.com/events.json)  
?

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [January 28, 2019, 8:42pm UTC](https://forum.getkirby.com/t/generating-json/12522/5 "2019-01-28T20:42:07Z")

</div>

should be this  
[https://website.com/programm.json](https://website.com/programm.json)

but make sure the regular template is working before setting up content representation…  
[https://website.com/programm](https://website.com/programm)

---

<div class="post-metadata">

**Author:** ![Perry](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/perry/32/1336_2.png) [@Perry](https://forum.getkirby.com/u/Perry)\
**Post date:** [January 28, 2019, 8:46pm UTC](https://forum.getkirby.com/t/generating-json/12522/6 "2019-01-28T20:46:28Z")

</div>

yes is working.

```
<main class="width-100 flex justify-content-center align-item-center">

    <?php foreach($page->children()->published() as $article): ?>

    <div><?php echo $article->title() ?></div>

    <?php endforeach ?>

    </main>
```

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [January 28, 2019, 9:03pm UTC](https://forum.getkirby.com/t/generating-json/12522/7 "2019-01-28T21:03:54Z")

</div>

try removing the logic in the content rep. maybe there is an issue there?

`<?php echo json_encode(['test']);`

---

<div class="post-metadata">

**Author:** ![Perry](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/perry/32/1336_2.png) [@Perry](https://forum.getkirby.com/u/Perry)\
**Post date:** [January 28, 2019, 9:57pm UTC](https://forum.getkirby.com/t/generating-json/12522/8 "2019-01-28T21:57:39Z")

</div>

no still the error page.  
my site is multi-language, can associate with it ?

---

<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:** [January 28, 2019, 10:06pm UTC](https://forum.getkirby.com/t/generating-json/12522/9 "2019-01-28T22:06:19Z")

</div>

Are you using the `/` root for the default language? Then =\> bug

> <https://github.com/getkirby/kirby/issues/1410>

---

<div class="post-metadata">

**Author:** ![Perry](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/perry/32/1336_2.png) [@Perry](https://forum.getkirby.com/u/Perry)\
**Post date:** [January 28, 2019, 10:10pm UTC](https://forum.getkirby.com/t/generating-json/12522/10 "2019-01-28T22:10:04Z")

</div>

oh yes!

```
<?php

return [
  'code' => 'de',
  'default' => true,
  'direction' => 'ltr',
  'locale' => 'de_DE',
  'name' => 'Deutsch',
  'url' => '/'
];
```

---

<div class="post-metadata">

**Author:** ![Perry](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/perry/32/1336_2.png) [@Perry](https://forum.getkirby.com/u/Perry)\
**Post date:** [January 28, 2019, 10:33pm UTC](https://forum.getkirby.com/t/generating-json/12522/11 "2019-01-28T22:33:17Z")

</div>

now it works, thank you 😃  
[https://site.com/de/programm.json](https://site.com/de/programm.json)

```
<?php

    return [
      'code' => 'de',
      'default' => true,
      'direction' => 'ltr',
      'locale' => 'de_DE',
      'name' => 'Deutsch',
      'url' => '/de'
    ];
```
