# How to transform JDBC input into a specific JSON format

**URL:** <https://discuss.elastic.co/t/how-to-transform-jdbc-input-into-a-specific-json-format/207012>\
**Category:** Logstash\
**Created:** [November 7, 2019, 9:44pm UTC](https://discuss.elastic.co/t/how-to-transform-jdbc-input-into-a-specific-json-format/207012 "2019-11-07T21:44:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![seePhor](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@seePhor](https://discuss.elastic.co/u/seePhor)\
**Post date:** [November 7, 2019, 9:44pm UTC](https://discuss.elastic.co/t/how-to-transform-jdbc-input-into-a-specific-json-format/207012/1 "2019-11-07T21:44:52Z")

</div>

Hello,

New to Logstash and trying to backfill a new Elasticsearch instance from a MySQL table using the JDBC input plugin. I have the input plugin working, but right now the output is just going to stdout.

I want to transform the input from the JDBC plugin to match a specific JSON format. For example, the query used in my JDBC input plugin will return:

```
"status_name" => "SENT",
"order_id" => 123,
"addr_line_1" => "123 Fake St"

```

I want the resulting JSON to look like:  
` { "recordHeader" : {"status": "SENT", "orderId": 123, "addressLine1": "123 Fake St"} }`

This involves renaming the column names returned from the JDBC input plugin and then putting the values in this new format. Is this something I can achieve using the mutate and add field transform plugins? Do I have to add a field that matches my new format and then remove the old field?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [November 7, 2019, 11:40pm UTC](https://discuss.elastic.co/t/how-to-transform-jdbc-input-into-a-specific-json-format/207012/2 "2019-11-07T23:40:56Z")

</div>

You could certainly do it with mutate. Personally I might use ruby

```
    ruby {
        code => '
            ["addr_line_1", "order_id", "status_name"].each { |k|
                event.set("[recordHeader][#{k}]", event.get(k))
                event.remove(k)
            }
        '
    }
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 5, 2019, 11:50pm UTC](https://discuss.elastic.co/t/how-to-transform-jdbc-input-into-a-specific-json-format/207012/4 "2019-12-05T23:50:51Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
