Question: I have a JSON with lots of empty content:

```
{
    "items": [
        {
            "category": "login",
            "fields": [
                {
                    "label": "Name",
                    "value": "",
                },
                {
                    "label": "E-Mail",
                    "value": "",
                },
                {
                    "label": "Password",
                    "value": "123456",
                },
                {
                    "label": "Website",
                    "fields": [
                        {
                            "label": "Name X",
                            "value": ""
                        },
                        {
                            "label": "Name Y",
                            "value": "another one"
                        },…
                    ]
                },…
            ]
        },…
    ]
}

```

The nesting goes several levels deeper. This shows only the first level. I want to delete all elements of "fields" (or whatever the array's key in deeper levels is), where their "value" is empty.

```
{
    "items": [
        {
            "category": "login",
            "fields": [
                {
                    "label": "Password",
                    "value": "123456",
                },
                {
                    "label": "Website",
                    "fields": [
                        {
                            "label": "Name Y",
                            "value": "another one"
                        },…
                    ]
                },…
            ]
        },…
    ]
}

```

How can I do this in Javascript?

Answer: 
Well, I found a way to iterate through the JSON object:

```
function remove(jsondata) {
  for (let i in jsondata) {
    if (jsondata[i].value != undefined && jsondata[i].value == '') {
       delete jsondata[i];
    }
    else if (typeof jsondata[i] === "object") remove(jsondata[i]);
  }
}

```

Not sure, if it's the most elegant way, but it works so far.
We use [object-scan](https://github.com/blackflux/object-scan) for many data processing tasks. It's powerful once you wrap your head around it. Here is how you could answer your questions

```js
// const objectScan = require('object-scan');

const prune = (input) => objectScan(['**[*].value'], {
  rtn: 'count',
  filterFn: ({ gparent, gproperty, value }) => {
    if (value === '') {
      gparent.splice(gproperty, 1);
      return true;
    }
    return false;
  }
})(input);

const obj = { items: [{ category: 'login', fields: [{ label: 'Name', value: '' }, { label: 'E-Mail', value: '' }, { label: 'Password', value: '123456' }, { label: 'Website', fields: [{ label: 'Name X', value: '' }, { label: 'Name Y', value: 'another one' }] }] }] };

console.log(prune(obj)); // return count of pruned entries
// => 3
console.log(obj);
// => { items: [ { category: 'login', fields: [ { label: 'Password', value: '123456' }, { label: 'Website', fields: [ { label: 'Name Y', value: 'another one' } ] } ] } ] }
```

```css
.as-console-wrapper {max-height: 100% !important; top: 0}
```

```html
<script src="https://bundle.run/object-scan@16.0.0"></script>
```

*Disclaimer*: I'm the author of [object-scan](https://www.npmjs.com/package/object-scan)