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!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...