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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...