# How to write a json values from a field in sql into elasticsearch using logstash

**URL:** <https://discuss.elastic.co/t/how-to-write-a-json-values-from-a-field-in-sql-into-elasticsearch-using-logstash/61514>\
**Category:** Logstash\
**Created:** [September 26, 2016, 2:07pm UTC](https://discuss.elastic.co/t/how-to-write-a-json-values-from-a-field-in-sql-into-elasticsearch-using-logstash/61514 "2016-09-26T14:07:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![saisn](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@saisn](https://discuss.elastic.co/u/saisn)\
**Post date:** [September 26, 2016, 2:07pm UTC](https://discuss.elastic.co/t/how-to-write-a-json-values-from-a-field-in-sql-into-elasticsearch-using-logstash/61514/1 "2016-09-26T14:07:50Z")

</div>

I have a table in sql server which has json objects as a value in one of the columns. My requirement is to read those objects as it is and write into an index. I would like to know what are the best ways of doing it using logstash and how it can be achieved.

## eg:

## type | response

submitapi | {"abc":"xxxx","xyz":{[xxx],[xxx]}  
calcapi | {"abc":"xxxx","xyz":{[xxx],[xxx]}  
checkinapi | {"abc":"xxxx","xyz":{[xxx],[xxx]}

I need the values under response to be stored into an index **without having the 'type' column as key**.

thanks

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 26, 2016, 2:21pm UTC](https://discuss.elastic.co/t/how-to-write-a-json-values-from-a-field-in-sql-into-elasticsearch-using-logstash/61514/2 "2016-09-26T14:21:00Z")

</div>

Use the jdbc input to read from the database table. I suppose you want to parse the JSON string in the "response" column so that "abc" and "xyz" end up as separate Elasticsearch fields? Use the json filter for that.

---

<div class="post-metadata">

**Author:** ![saisn](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@saisn](https://discuss.elastic.co/u/saisn)\
**Post date:** [September 26, 2016, 2:33pm UTC](https://discuss.elastic.co/t/how-to-write-a-json-values-from-a-field-in-sql-into-elasticsearch-using-logstash/61514/3 "2016-09-26T14:33:39Z")

</div>

I can use the jdbc plugin but it creates "response" as a key and value as json but i just need the value as an object.

expected in elasticsearch:  
"response":"{"abc":"xxxx","xyz":{[xxx],[xxx]}"  
required in elasticsearch:  
{"abc":"xxxx","xyz":{[xxx],[xxx]}

Thanks

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 26, 2016, 2:35pm UTC](https://discuss.elastic.co/t/how-to-write-a-json-values-from-a-field-in-sql-into-elasticsearch-using-logstash/61514/4 "2016-09-26T14:35:04Z")

</div>

Again, use the json filter.

```nohighlight
json {
  source => "response"
}

```

---

<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:** [July 6, 2017, 4:36am UTC](https://discuss.elastic.co/t/how-to-write-a-json-values-from-a-field-in-sql-into-elasticsearch-using-logstash/61514/5 "2017-07-06T04:36:51Z")

</div>


