<?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 Re: Multi field combination for JSON file question in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Multi-field-combination-for-JSON-file-question/m-p/491964#M84091</link>
    <description>&lt;P&gt;@darkelfaxe, if your issue is that you are getting a multi-value results from your JSON, try adding the following to your existing query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="main" resource online Status
| head 1
| fields "EventData.Values{}.Name" "EventData.Values{}.Status"
| rename "EventData.Values{}.*" as "*"
| eval EventData=mvzip(Name,Status)
| fields EventData
| mvexpand EventData
| makemv EventData delim=","
| eval RESOURCE=mvindex(EventData,0),STATUS=mvindex(EventData,1)
| streamstats count as ID
| fields ID STATUS RESOURCE
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please try out and confirm.&lt;BR /&gt;
Following is a run anywhere example based on the sample data provided:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="{\"EventType\":2,\"EventData\":{\"Values\":[{\"Status\":1,\"Name\":\"BOT1\"},{\"Status\":0,\"Name\":\"BOT2\"},{\"Status\":0,\"Name\":\"BOT3\"},{\"Status\":1,\"Name\":\"BOT4\"}],\"Subject\":\"Resource Online Status\",\"Source\":\"Dashboard\"}}"
| spath
| head 1
| table "EventData.Values{}.Name" "EventData.Values{}.Status"
| rename "EventData.Values{}.*" as "*"
| eval EventData=mvzip(Name,Status)
| fields EventData
| mvexpand EventData
| makemv EventData delim=","
| eval RESOURCE=mvindex(EventData,0),STATUS=mvindex(EventData,1)
| streamstats count as ID
| fields ID STATUS RESOURCE
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS:&lt;BR /&gt;
1. &lt;CODE&gt;table&lt;/CODE&gt; is a transforming command, you should avoid use &lt;CODE&gt;fields&lt;/CODE&gt; instead.&lt;BR /&gt;
2. Splunk events are sorted in reverse chronological order by default i.e. &lt;CODE&gt;sort - _time&lt;/CODE&gt; just consumes performance if you are only interested in latest event. &lt;BR /&gt;
3. &lt;CODE&gt;head 1&lt;/CODE&gt; should be first pipe after index search as it pulls only one event from indexer. This should improve performance of your search.&lt;/P&gt;

&lt;P&gt;Refer to &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Search/Writebettersearches"&gt;Writing Better Searches&lt;/A&gt; Splunk documentation to better understand above points.&lt;/P&gt;</description>
    <pubDate>Sun, 15 Mar 2020 19:50:36 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2020-03-15T19:50:36Z</dc:date>
    <item>
      <title>Multi field combination for JSON file question</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Multi-field-combination-for-JSON-file-question/m-p/491963#M84090</link>
      <description>&lt;P&gt;I'm totally new to splunk, I have this JSON file already indexed:&lt;/P&gt;

&lt;P&gt;{"EventType":2,"EventData":{"Values":[{"Status":1,"Name":"BOT1"},{"Status":0,"Name":"BOT2"},{"Status":0,"Name":"BOT3"},{"Status":1,"Name":"BOT4"}],"Subject":"Resource Online Status","Source":"Dashboard"}}&lt;/P&gt;

&lt;P&gt;I need to create a table which contains the Values in separate columns like this:&lt;/P&gt;

&lt;P&gt;ID  STATUS    RESOURCE&lt;BR /&gt;
1          1                BOT1&lt;BR /&gt;
2          0                BOT2&lt;BR /&gt;
3          0                BOT3&lt;BR /&gt;
4          1                BOT4&lt;/P&gt;

&lt;P&gt;I'm trying the following:&lt;BR /&gt;
index="main" resource online Status | table "EventData.Values{}.Name" "EventData.Values{}.Status" | sort -_time asc | head 1&lt;BR /&gt;
But it gives me this:&lt;/P&gt;

&lt;P&gt;ID   EventData.Values{}.Name     EventData.Values{}.Status&lt;BR /&gt;
1     BOT1 BOT2 BOT3 BOT4         1 0  0 1&lt;/P&gt;

&lt;P&gt;How can I combine the two columns to generate the desired format?&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 15 Mar 2020 17:39:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Multi-field-combination-for-JSON-file-question/m-p/491963#M84090</guid>
      <dc:creator>darkelfaxe</dc:creator>
      <dc:date>2020-03-15T17:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: Multi field combination for JSON file question</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Multi-field-combination-for-JSON-file-question/m-p/491964#M84091</link>
      <description>&lt;P&gt;@darkelfaxe, if your issue is that you are getting a multi-value results from your JSON, try adding the following to your existing query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="main" resource online Status
| head 1
| fields "EventData.Values{}.Name" "EventData.Values{}.Status"
| rename "EventData.Values{}.*" as "*"
| eval EventData=mvzip(Name,Status)
| fields EventData
| mvexpand EventData
| makemv EventData delim=","
| eval RESOURCE=mvindex(EventData,0),STATUS=mvindex(EventData,1)
| streamstats count as ID
| fields ID STATUS RESOURCE
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please try out and confirm.&lt;BR /&gt;
Following is a run anywhere example based on the sample data provided:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="{\"EventType\":2,\"EventData\":{\"Values\":[{\"Status\":1,\"Name\":\"BOT1\"},{\"Status\":0,\"Name\":\"BOT2\"},{\"Status\":0,\"Name\":\"BOT3\"},{\"Status\":1,\"Name\":\"BOT4\"}],\"Subject\":\"Resource Online Status\",\"Source\":\"Dashboard\"}}"
| spath
| head 1
| table "EventData.Values{}.Name" "EventData.Values{}.Status"
| rename "EventData.Values{}.*" as "*"
| eval EventData=mvzip(Name,Status)
| fields EventData
| mvexpand EventData
| makemv EventData delim=","
| eval RESOURCE=mvindex(EventData,0),STATUS=mvindex(EventData,1)
| streamstats count as ID
| fields ID STATUS RESOURCE
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS:&lt;BR /&gt;
1. &lt;CODE&gt;table&lt;/CODE&gt; is a transforming command, you should avoid use &lt;CODE&gt;fields&lt;/CODE&gt; instead.&lt;BR /&gt;
2. Splunk events are sorted in reverse chronological order by default i.e. &lt;CODE&gt;sort - _time&lt;/CODE&gt; just consumes performance if you are only interested in latest event. &lt;BR /&gt;
3. &lt;CODE&gt;head 1&lt;/CODE&gt; should be first pipe after index search as it pulls only one event from indexer. This should improve performance of your search.&lt;/P&gt;

&lt;P&gt;Refer to &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Search/Writebettersearches"&gt;Writing Better Searches&lt;/A&gt; Splunk documentation to better understand above points.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Mar 2020 19:50:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Multi-field-combination-for-JSON-file-question/m-p/491964#M84091</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-03-15T19:50:36Z</dc:date>
    </item>
  </channel>
</rss>

