# Json collection?

**URL:** <https://discourse.getcockpit.com/t/json-collection/1131>\
**Category:** Support\
**Created:** [December 20, 2019, 2:06pm UTC](https://discourse.getcockpit.com/t/json-collection/1131 "2019-12-20T14:06:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aolko](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/aolko/32/458_2.png) [@aolko](https://discourse.getcockpit.com/u/aolko)\
**Post date:** [December 20, 2019, 2:06pm UTC](https://discourse.getcockpit.com/t/json-collection/1131/1 "2019-12-20T14:06:09Z")

</div>

Is it possible to make a collection that outputs json like this one? Want to make a calendar events editing a bit more easier.

> **json**
>
> ```
> { 
> "data":[
> {
> "id":"1",
> "start_date":"2019-12-02 00:00:00",
> "end_date":"2019-12-04 00:00:00",
> "text":"dblclick me!",
> "color":"red",
> "type":"1"
> },
> {
> "id":"2",
> "start_date":"2019-12-09 00:00:00",
> "end_date":"2019-12-11 00:00:00",
> "text":"and me!",
> "type":"2"
> },
> {
> "id":"3",
> "start_date":"2019-12-16 00:00:00",
> "end_date":"2019-12-18 00:00:00",
> "text":"and me too!",
> "type":"3"
> },
> { 
> "id":"4",
> "start_date":"2019-12-02 08:00:00",
> "end_date":"2019-12-02 14:10:00",
> "text":"Type 2 event",
> "type":"2"
> }
> ], 
> "collections": {
> "sections":[
> {"value":"1","label":"Simple"},
> {"value":"2","label":"Complex"},
> {"value":"3","label":"Unknown"}
> ]
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![aolko](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/aolko/32/458_2.png) [@aolko](https://discourse.getcockpit.com/u/aolko)\
**Post date:** [December 24, 2019, 12:07pm UTC](https://discourse.getcockpit.com/t/json-collection/1131/2 "2019-12-24T12:07:39Z")

</div>

Hello? Does anyone even care?

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [December 27, 2019, 9:55am UTC](https://discourse.getcockpit.com/t/json-collection/1131/3 "2019-12-27T09:55:03Z")

</div>

Hello, we are still a small community and we contribute and help in our spare time - and it was Christmas.

Your question:

It is possible, but you have to do multiple steps.

**Create a collection with your fields.**

If you don’t need numeric ids, you can use the default `_id` field with mongodb id style.

For `start_date` and `end_date`, you can use the date field. If you need the part ` 00:00:00` in your output, you can copy and paste the [date field component file](https://github.com/agentejo/cockpit/blob/next/modules/Cockpit/assets/components/field-date.tag) into `path/to/cockpit/config/tags/field-date.tag` and modifiy it to produce your exact date format. This way, the core component will be overwritten.

Use a select field for `type`.

You can create your own field components, if you want to. I needed a custom date range field in the past and published it for inspiration: [https://github.com/raffaelj/cockpit-scripts/blob/master/custom-fields/field-date-range.tag](https://github.com/raffaelj/cockpit-scripts/blob/master/custom-fields/field-date-range.tag)

**Custom rest api output**

You can create your own api endpoint, that produces the format, you want. Create a file `/cockpit/config/api/myCustomEndpoint.php` and return your format.

```php
<?php

$data = cockpit('collections')->find('calendar');

$collections = ['sections' => ['...' => '...']];

return compact('data', 'collections');

```

---

<div class="post-metadata">

**Author:** ![olga.botezatu](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@olga.botezatu](https://discourse.getcockpit.com/u/olga.botezatu)\
**Post date:** [March 26, 2024, 7:01pm UTC](https://discourse.getcockpit.com/t/json-collection/1131/4 "2024-03-26T19:01:26Z")

</div>

Yes, it’s entirely possible to create a collection of calendar events that outputs JSON in the desired format. Below is an example of how you could structure your JSON:  
{  
“events”: [  
{  
“id”: 1,  
“title”: “Meeting with Client”,  
“start”: “2024-03-10T09:00:00”,  
“end”: “2024-03-10T11:00:00”,  
“location”: “Conference Room A”,  
“description”: “Discuss project requirements and timelines.”  
},  
{  
“id”: 2,  
“title”: “Team Lunch”,  
“start”: “2024-03-12T12:30:00”,  
“end”: “2024-03-12T13:30:00”,  
“location”: “Cafeteria”,  
“description”: “Team building and bonding session.”  
},  
{  
“id”: 3,  
“title”: “Product Launch”,  
“start”: “2024-03-15T10:00:00”,  
“end”: “2024-03-15T12:00:00”,  
“location”: “Main Auditorium”,  
“description”: “Launch of new product line.”  
}  
]  
}
