# Flat JSON

{% hint style="info" %}
See the changelog of this Action type [here](https://app.gitbook.com/s/IXj83By4f20oCrZZ0gyP/flat-json).
{% endhint %}

{% hint style="warning" %}
**Deprecated operation**

This operation has been deprecated and is no longer supported. We recommend using the [JSON Transformation](https://docs.onum.com/the-workspace/pipelines/actions/transformation/json-transformation) operation as its replacement.
{% endhint %}

## Overview

The **Flat JSON** Action converts a nested JSON into a new, flattened JSON field with only one layer of key/value pairs.

<figure><picture><source srcset="https://965373739-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkxZeV4nlXcIAjMGZxzLI%2Fuploads%2F3ilP3h06Avcld5fJ2vyY%2Fgggg.png?alt=media&#x26;token=7b8a340c-66d5-4cef-8bd9-91bb54c75ce6" media="(prefers-color-scheme: dark)"><img src="https://965373739-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkxZeV4nlXcIAjMGZxzLI%2Fuploads%2FsYi20twiJzhKBXoym8dw%2Flkok.png?alt=media&#x26;token=a4c7b390-2a46-4119-93fe-694f267e2672" alt=""></picture><figcaption></figcaption></figure>

{% hint style="warning" %}
In order to configure this action, you must first link it to a Listener. Go to [Building a Pipeline ](https://docs.onum.com/the-workspace/pipelines/building-a-pipeline)to learn how to link.
{% endhint %}

## Ports

These are the input and output ports of this Action:

<details>

<summary>Input ports</summary>

* **Default port** - All the events to be processed by this Action enter through this port.

</details>

<details>

<summary>Output ports</summary>

* **Default port** - Events are sent through this port if no error occurs while processing them.
* **Error port** - Events are sent through this port if an error occurs while processing them.

</details>

## Configuration

{% stepper %}
{% step %}
Find **Flat JSON** in the **Actions** tab (under the **Transformation** group) and drag it onto the canvas.
{% endstep %}

{% step %}
To open the configuration, click the Action in the canvas and select **Configuration**.
{% endstep %}

{% step %}
Enter the required parameters:

<table><thead><tr><th width="218">Parameter</th><th>Description</th><th data-hidden></th></tr></thead><tbody><tr><td><strong>Field that holds the JSON</strong><mark style="color:red;"><strong>*</strong></mark></td><td>Select the field that contains the JSON values from the incoming data.</td><td></td></tr><tr><td><strong>Field where the flatten JSON will be stored</strong><mark style="color:red;"><strong>*</strong></mark></td><td>Give a name to the field that will store the flattened JSON values.</td><td></td></tr><tr><td><strong>Flatten level</strong> </td><td>Set the number of levels to flatten to.</td><td></td></tr><tr><td><strong>Separator</strong></td><td>Choose to separate values with <em><code>_</code></em> or <em><code>.</code></em> (<em><code>_</code></em> by default).</td><td></td></tr></tbody></table>
{% endstep %}

{% step %}
Click **Save** to complete the process.
{% endstep %}
{% endstepper %}

## Example

You wish to flatten a JSON to level 3 hierarchy.

{% stepper %}
{% step %}

### Raw JSON

Your input data contains the following raw JSON file:

```
[
  {
    "username": "user_1",
    "method": "POST",
    "endpoint": "breach log",
    "ip": "10.XXX.XX.XX",
    "description": "[Role] User performed an action on breach log",
    "viewport": [1920, 955],
    "usage": true
  },
  {
    "username": "user_1",
    "method": "POST",
    "endpoint": "event log",
    "ip": "10.XXX.XX.XX",
    "description": "[Role] User performed an action on event log from breach log",
    "viewport": [1920, 955],
    "usage": true
  },
  {
    "username": "service_user",
    "method": "POST",
    "endpoint": "/admin/age",
    "ip": "127.0.0.1",
    "status": 400
  },
  {
    "username": "user_2",
    "method": "POST",
    "endpoint": "/sso/login",
    "ip": "10.XXX.XX.XX",
    "status": 302
  }
]
```

You can add a [Parser](https://docs.onum.com/the-workspace/pipelines/actions/transformation/parser) and paste this data as raw data to generate the event.
{% endstep %}

{% step %}

### Flat JSON

Add the **Flat JSON** Action to the canvas and enter the following:

* **Field that holds the JSON -** `msg`
* **Field where the flatten JSON will be stored** - give your new field a name e.g. `Flattened`
* **Flatten level** - `3`
  {% endstep %}

{% step %}

### Results

The **Flat JSON** Action now has an output field that will send the JSON flattened to a level 3 hierarchy:

```
[
  {
    "username": "user_1",
    "method": "POST",
    "endpoint": "breach log",
    "ip": "10.XXX.XX.XX",
    "description": "[Role] User performed an action on breach log",
    "usage": true,
    "viewport_dimensions": {
      "width": 1920,
      "height": 955
    }
  },
  {
    "username": "user_1",
    "method": "POST",
    "endpoint": "event log",
    "ip": "10.XXX.XX.XX",
    "description": "[Role] User performed an action on event log from breach log",
    "usage": true,
    "viewport_dimensions": {
      "width": 1920,
      "height": 955
    }
  },
  {
    "username": "service_user",
    "method": "POST",
    "endpoint": "/admin/age",
    "ip": "127.0.0.1",
    "status": 400
  },
  {
    "username": "user_2",
    "method": "POST",
    "endpoint": "/sso/login",
    "ip": "10.XXX.XX.XX",
    "status": 302
  }
]
```

{% endstep %}
{% endstepper %}
