Splunk Search

From InputStream to JsonArray

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>();



    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

New Member
0 Karma


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

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