Getting Data In

Order of fields in json java

1234testtest
Path Finder

For java sdk, output mode as json, I am getting fields sent from splunk and their values as json. But how ever is the order of fields in the table statement
| table field1, field2
or
| table field2, field1

The order of fields I get in the java side is the same - and i need the order the same way as I has specified in the query after table
What should be done to get this way

Tags (1)
0 Karma

Neeraj_Luthra
Splunk Employee
Splunk Employee

It should honor the fields specified in the query string after the table keyword. If possible, try to run the query through cURL and see whether you get the desired results. Nonetheless, you can pass the list of fields explicitly to the getResults method on the job, once its done.

JobResultsArgs resultArgs = new JobResultsArgs();
resultArgs.setFieldList(new String[] {"field1", "field2"});
InputStream results = job.getResults(resultArgs);

0 Karma

1234testtest
Path Finder

Yes the order in java is different from what I specify in query after table keyword. Also FYI I am using output mode as json in java side to get details from plunk

0 Karma

Neeraj_Luthra
Splunk Employee
Splunk Employee

I am not sure what the problem is. Can you clarify further? Is the order in Java different from what your query is specifying after the table keyword?

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...