# Logstash - Converting input from JDBC to json for an HTTP request

**URL:** <https://discuss.elastic.co/t/logstash-converting-input-from-jdbc-to-json-for-an-http-request/322949>\
**Category:** Logstash\
**Created:** [January 11, 2023, 3:32pm UTC](https://discuss.elastic.co/t/logstash-converting-input-from-jdbc-to-json-for-an-http-request/322949 "2023-01-11T15:32:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![L\_C](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/l_c/32/81108_2.png) [@L\_C](https://discuss.elastic.co/u/L_C)\
**Post date:** [January 11, 2023, 3:32pm UTC](https://discuss.elastic.co/t/logstash-converting-input-from-jdbc-to-json-for-an-http-request/322949/1 "2023-01-11T15:32:47Z")

</div>

Hello,

I am looking for some pointers regarding how to convert input data from a JBDC plugin into json to send the content to an API.

Here is the logstash.conf:

```auto
input {
  jdbc {
    jdbc_driver_library => "/logstash-core/lib/jars/mssql-jdbc-11.2.0.jre11.jar"
    jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    jdbc_connection_string => "jdbc:sqlserver://servert:1433;databaseName=db;encrypt=false;trustServerCertificate=true;"
    jdbc_user => "admin"
    jdbc_password => "pass"
    statement => "SELECT * from Metadata WHERE CreatedDate > :sql_last_value" # Comparison based on the latest value it ingested
    schedule => "* * * * *" # => Polling is just a cronjob
    use_column_value => true # Enables you to use one of the entry column to save as sql_last_value
    tracking_column => "createddate" # Select the entry column to use, must be lowercase regardless of your column casing (otherwise by default it uses the last entry process time which is not accurate enough)
    tracking_column_type => "timestamp" # Select the type
    type => "db-logs-access"
    last_run_metadata_path => "/usr/share/logstash/temporary/lastvalues_persistence/state_sql_last_value.yml" # Guarantuees persistence of the last_sql_value if the service restarts
    target => "message"
  }
  stdin {
    codec => "json"
  }  
}

filter
{
  json {
      source => "message"
      target => "parsed"
  }
  http {
    url => "http://myapi.com/api/enrichment?site=siteA"
    verb => "POST"
    body => "%{[message]}"
    body_format => "json"
    target_body => "api_response"
  }
}

output {
  stdout { codec => rubydebug }
  elasticsearch {
    hosts => ["url/"]
    index => "xyz_index"
	  document_id => "%{[itemid]}"
    user => "elastic"
    password => "pass"
  }
}

```

When i try to parse the input as json, the fomat is indeed different:  
`WARN ] 2023-01-11 15:25:02.887 [[pipeline_1]>worker0] json - Error parsing json {:source=>"message", :raw=>{"docname"=>"THE UNITED KINGDOM", "title"=>nil"....}`

Is there anything to do with the JBDC plugin in order to have data as json?

Thanks,  
BR,  
L

---

<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:** [February 8, 2023, 3:33pm UTC](https://discuss.elastic.co/t/logstash-converting-input-from-jdbc-to-json-for-an-http-request/322949/2 "2023-02-08T15:33:20Z")

</div>

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