Splunk Search

From InputStream to JsonArray

kalyani1184
New Member

I would like to know how to get a Json array from an InputStream Object.

Actually I am trying to store some splunk raw parameters like host, sourcetype, and source in a string list and then passed into JobResultArgs. Then passed into InputStream as a Job object. Now i want that to be passed to a Json Array to get the result size and pass throught the array and get the host and source objects.

JobResultsArgs jobRes = new JobResultsArgs();

      List<String> fields = new ArrayList<String>();

    fields.add("_raw");
    fields.add("host");
    fields.add("sourcetype");
    fields.add("source");

    jobRes.setFieldList((String[])fields.toArray());
    jobRes.setCount(2500);


    InputStream inpStream = job.getResults(jobRes);  
    ResultsReaderJson Jsa = new ResultsReaderJson(inpStream);

      //      System.out.println("result size: " + Jsa.size());
     //  for(int i = 0; i < Jsa.size(); i++) {


   //   JsonElement hostElement = Jsa.get(i).getAsJsonObject().get("host");
  //    JsonElement source = Jsa.get(i).getAsJsonObject().get("source");

The commented lines are not compatable with the code but i want to implement this kind of code. Is there a way i can get a Json Array from the InputStream

0 Karma

aryank4564
New Member
0 Karma

martin_mueller
SplunkTrust
SplunkTrust

For the commented part you may be looking for ResultsReader.getNextEvent(): http://docs.splunk.com/DocumentationStatic/JavaSDK/1.0/index.html?com/splunk/ResultsReader.html

0 Karma

kalyani1184
New Member

Thank you for the response. I looked previously but that was not i wanted. I wanted to get the size of it and the host name source name which i could not find from that.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...