All Apps and Add-ons

Splunk DB Connect 2: How to convert DB input data obtained using dbxquery from JSON format to key value format?

dsuryaavinash
Explorer

The default format of the results obtained using “dbxquery” has changed to JSON format. Can you please advise us on how to convert the DB results we get using the dbxquery command to the column name=Key and rown=Value format? Any config file changes will accomplish this task to get data as retrieved in DB Connect 1?

1 Solution

mweissha
Path Finder

Have you tried using the shortnames argument for dbxquery?

eg: |dbxquery connection="whatever" query="SELECT%20id,name%20FROM%20table" shortnames=x | dedup name

I'm not sure if this helps to answer but it worked for me to identify fields from dbxquery which you can then manipulate using SPL with things like dedup, sort, etc. It doesn't seem to matter what you assign to shortnames, you'll notice if you run the search that your SQL results will be assigned as fields instead of JSON data.

http://docs.splunk.com/Documentation/DBX/2.0.4/DeployDBX/Commands

View solution in original post

hsesterhenn
Path Finder

Hi,

in addition, to get a table again, you can add two commands:

...| fields -_raw | table *

Even if the raw events are still displayed as a JSON object with long names you'll get a table like with DBConnect 1.x (and short column names).

HTH,

Holger

mweissha
Path Finder

Have you tried using the shortnames argument for dbxquery?

eg: |dbxquery connection="whatever" query="SELECT%20id,name%20FROM%20table" shortnames=x | dedup name

I'm not sure if this helps to answer but it worked for me to identify fields from dbxquery which you can then manipulate using SPL with things like dedup, sort, etc. It doesn't seem to matter what you assign to shortnames, you'll notice if you run the search that your SQL results will be assigned as fields instead of JSON data.

http://docs.splunk.com/Documentation/DBX/2.0.4/DeployDBX/Commands

nyc_jason
Splunk Employee
Splunk Employee

in v2.2 you can also add the argument output=csv which will omit the _raw and _time fields.

|dbxquery connection="whatever" query="SELECT%20id,name%20FROM%20table" output=csv shortnames=true | dedup name
0 Karma

dsuryaavinash
Explorer

Thank you , Wow that worked , i somehow missed it

0 Karma

mweissha
Path Finder

You're welcome. Glad it worked. I was scratching my head for a few days myself before I ran into that solution.

0 Karma
Get Updates on the Splunk Community!

Don't wait! Accept the Mission Possible: Splunk Adoption Challenge Now and Win ...

Attention everyone! We have exciting news to share! We are recruiting new members for the Mission Possible: ...

Unify Your SecOps with Splunk Mission Control

In today’s post, I'm excited to share some recent Splunk Mission Control innovations. With Splunk Mission ...

Data Preparation Made Easy: SPL2 for Edge Processor

By now, you may have heard the exciting news that Edge Processor, the easy-to-use Splunk data preparation tool ...