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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Build the Future of Agentic AI: Join the Splunk Agentic Ops Hackathon

AI is changing how teams investigate incidents, detect threats, automate workflows, and build intelligent ...

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...