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!

The Splunk Success Framework: Your Guide to Successful Splunk Implementations

Splunk Lantern is a customer success center that provides advice from Splunk experts on valuable data ...

Splunk Training for All: Meet Aspiring Cybersecurity Analyst, Marc Alicea

Splunk Education believes in the value of training and certification in today’s rapidly-changing data-driven ...

Investigate Security and Threat Detection with VirusTotal and Splunk Integration

As security threats and their complexities surge, security analysts deal with increased challenges and ...