# flattenObject

Canonical: https://docs.shumoku.dev/en/library/api/flattenObject
Language: en

@shumoku/core · 0.4.0 · function

# flattenObject

[Source](https://github.com/konoe-akitoshi/shumoku/blob/main/libs/@shumoku/core/src/plugin-kit/metrics-flatten.ts#L24)

Flatten an arbitrary upstream record into \`DiscoveredMetric\[\]\` for the plugin "All metrics" passthrough panel. This is the generic dumper every \`HostsCapable\` plugin should use instead of hand-enumerating fields (which is how zabbix ended up coercing every value to a number and dropping categorical attributes). Walk the object: - object children join into the metric name with \`\_\` (\`{ a: { b: 1 } }\` with prefix \`p\` → \`p\_a\_b\`), - array-of-primitives emits a \`<name>\_count\`, - array-of-objects emits a \`<name>\_count\` then expands each element with a \`<key>\_index\` label, - null / undefined / empty-string / non-finite leaves are skipped as noise. Lifted verbatim (behavior-preserving) from the aruba-instant-on plugin, which had the only correct generic implementation.

```
flattenObject(obj: unknown, prefix: string, labels?: Record<string, string>): DiscoveredMetric[]
```

## Parameters

| Parameter | Type | Description | Default |
| --- | --- | --- | --- |
| `obj` | `unknown` | No additional description. | `—` |
| `prefix` | `string` | No additional description. | `—` |
| `labels` | `Record<string, string>` | No additional description. | `{}` |

## Returns

```
DiscoveredMetric[]
```

[`libs/@shumoku/core/src/plugin-kit/metrics-flatten.ts:24`](https://github.com/konoe-akitoshi/shumoku/blob/main/libs/@shumoku/core/src/plugin-kit/metrics-flatten.ts#L24)
