<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do I get json_cols instead of json_rows in my reporting command? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-get-json-cols-instead-of-json-rows-in-my-reporting/m-p/455581#M78784</link>
    <description>&lt;P&gt;Hey everyone,&lt;/P&gt;

&lt;P&gt;I'm currently writing a custom search command for some reporting and I'm struggling with the result format that I get. Usually you get an array of json events that can be used for streaming commands, however what I need is an array of columns, where each element contains all values from a column of the resultset. &lt;/P&gt;

&lt;P&gt;I know that in Splunk's internal libraries there is a function called "setFetchOptions()" which is also used by some visualizations to gather the results in a column array instead of row array, however I couldn't find an implementation of it directly. &lt;/P&gt;

&lt;P&gt;from pdfgen_endpoint.py, line 698:&lt;BR /&gt;
&lt;CODE&gt;view.getSearchJobObj().setFetchOptions(output_mode="json_cols", time_format=pt.TIME_RAW_FORMAT)&lt;BR /&gt;
results = view.getSearchJobResults() &lt;BR /&gt;
&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I know that I can create this column array manually by iterating over the resultset like this:&lt;BR /&gt;
&lt;CODE&gt;data = list()&lt;BR /&gt;
 for key in results[0].keys():&lt;BR /&gt;
    column = list()&lt;BR /&gt;
    for r in results:&lt;BR /&gt;
        column.append(r[key])&lt;BR /&gt;
    data.append(column)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;However I thought that maybe someone knows a more convenient, so to say: Splunk way of doing it. &lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 20:35:16 GMT</pubDate>
    <dc:creator>bojanjanisch</dc:creator>
    <dc:date>2020-09-29T20:35:16Z</dc:date>
    <item>
      <title>How do I get json_cols instead of json_rows in my reporting command?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-get-json-cols-instead-of-json-rows-in-my-reporting/m-p/455581#M78784</link>
      <description>&lt;P&gt;Hey everyone,&lt;/P&gt;

&lt;P&gt;I'm currently writing a custom search command for some reporting and I'm struggling with the result format that I get. Usually you get an array of json events that can be used for streaming commands, however what I need is an array of columns, where each element contains all values from a column of the resultset. &lt;/P&gt;

&lt;P&gt;I know that in Splunk's internal libraries there is a function called "setFetchOptions()" which is also used by some visualizations to gather the results in a column array instead of row array, however I couldn't find an implementation of it directly. &lt;/P&gt;

&lt;P&gt;from pdfgen_endpoint.py, line 698:&lt;BR /&gt;
&lt;CODE&gt;view.getSearchJobObj().setFetchOptions(output_mode="json_cols", time_format=pt.TIME_RAW_FORMAT)&lt;BR /&gt;
results = view.getSearchJobResults() &lt;BR /&gt;
&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I know that I can create this column array manually by iterating over the resultset like this:&lt;BR /&gt;
&lt;CODE&gt;data = list()&lt;BR /&gt;
 for key in results[0].keys():&lt;BR /&gt;
    column = list()&lt;BR /&gt;
    for r in results:&lt;BR /&gt;
        column.append(r[key])&lt;BR /&gt;
    data.append(column)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;However I thought that maybe someone knows a more convenient, so to say: Splunk way of doing it. &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:35:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-get-json-cols-instead-of-json-rows-in-my-reporting/m-p/455581#M78784</guid>
      <dc:creator>bojanjanisch</dc:creator>
      <dc:date>2020-09-29T20:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get json_cols instead of json_rows in my reporting command?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-get-json-cols-instead-of-json-rows-in-my-reporting/m-p/455582#M78785</link>
      <description>&lt;P&gt;Better format of code:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;view.getSearchJobObj().setFetchOptions(output_mode="json_cols", time_format=pt.TIME_RAW_FORMAT)&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;results = view.getSearchJobResults()&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;and&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;data = list()&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;for key in results[0].keys():&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;column = list()&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;for r in results:&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;column.append(r[key])&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;data.append(column)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Sorry for this comment, I couldn't find an option to edit it anymore.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 11:14:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-get-json-cols-instead-of-json-rows-in-my-reporting/m-p/455582#M78785</guid>
      <dc:creator>bojanjanisch</dc:creator>
      <dc:date>2018-07-23T11:14:12Z</dc:date>
    </item>
  </channel>
</rss>

