# Squash "value" key in JSON

**URL:** <https://discourse.getcockpit.com/t/squash-value-key-in-json/1619>\
**Category:** Support\
**Created:** [September 8, 2020, 6:13pm UTC](https://discourse.getcockpit.com/t/squash-value-key-in-json/1619 "2020-09-08T18:13:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![prisonerjohn](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/prisonerjohn/32/667_2.png) [@prisonerjohn](https://discourse.getcockpit.com/u/prisonerjohn)\
**Post date:** [September 8, 2020, 6:13pm UTC](https://discourse.getcockpit.com/t/squash-value-key-in-json/1619/1 "2020-09-08T18:13:45Z")

</div>

I’d like to change the format of the JSON generated from Repeater types to not include the “value” key and just skip it. For example, my data has a few Repeaters of Sets that end up with JSON that looks like:

```auto
...
...
"hints": [
{
    "value": {
        "image": "main\/image1.png",
        "prompt": "This is hint 1."
    }
},
{
    "value": {
        "image": "main\/image2.png",
        "prompt": "This is hint 2."
    }
}
],
...

```

and what I want is this:

```auto
...
"hints": [
{
    "image": "main\/image1.png",
    "prompt": "This is hint 1."
},
{
    "image": "main\/image2.png",
    "prompt": "This is hint 2."
}
],
...

```

I read [another post](https://discourse.getcockpit.com/t/array-of-strings-type-fieldtype/538) by @pauloamgomes that hints to using a hook which I’m trying to reference, but I need help getting it to work. This is what I have so far:

```auto
$app->on('collections.find.after', function($name, &$entries) use($app) {
  
  function simple_value(&$entry) {
    foreach ($entry as $name => &$value) {
      if (strcmp($name, 'value') == 0) {
        $entry[$name] = $value;
      }
      if (is_array($value) || is_object($value)) {
        foreach ($value as $key => &$child) {
          simple_value($child);
        }
      }
    }
  }

  simple_value($entries);
});

```

This doesn’t seem to do anything. Am I on the right track? Is there an easy way to debug this and see what’s going on? I’m a bit new to PHP and not familiar with the toolset.

Thanks!

---

<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:** [September 18, 2020, 2:40pm UTC](https://discourse.getcockpit.com/t/squash-value-key-in-json/1619/2 "2020-09-18T14:40:58Z")

</div>

> [@prisonerjohn](#):
>
> and what I want is this:

You could use a modified repeater field to store the data in your prefered way. I answered this a few days ago and updated my simple-repeater field to be compatible with set fields.

See: [Fieldtype to get array of objects - #2 by raffaelj](https://discourse.getcockpit.com/t/fieldtype-to-get-array-of-objects/1627/2)

> [@prisonerjohn](#):
>
> This doesn’t seem to do anything. […] I’m a bit new to PHP and not familiar with the toolset.

This one should work. Replace `collectionname` with the name of your collection, that contains the repeater fields.

```php
// don't convert found data while editing in backend
if (COCKPIT_API_REQUEST) {

    // Don't fire on all collections, but only on the one named "collectionname"
    $app->on('collections.find.after.collectionname', function($name, &$entries) {

        // iterate over entries and replace the values
        foreach ($entries as &$entry) {

            $entry = isset($entry['value']) ? $entry['value'] : null;

        }

    });

}

```
