<?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: Create a table based on values from two JSON payloads in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490022#M194113</link>
    <description>&lt;P&gt;what's index and sourcetype both?&lt;/P&gt;</description>
    <pubDate>Tue, 10 Mar 2020 00:26:00 GMT</pubDate>
    <dc:creator>to4kawa</dc:creator>
    <dc:date>2020-03-10T00:26:00Z</dc:date>
    <item>
      <title>Create a table based on values from two JSON payloads</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490021#M194112</link>
      <description>&lt;P&gt;Hi I've two different payloads returned from my search and I need to create a table from values extracted from the payloads, please find the find the payloads below&lt;/P&gt;

&lt;H2&gt;Payload 1&lt;/H2&gt;

&lt;HR /&gt;

&lt;P&gt;{   "appointment": {&lt;BR /&gt;
    "appointmentId": 0,&lt;BR /&gt;
    "key": "",&lt;BR /&gt;
    "Durations": 60,&lt;BR /&gt;
    &lt;STRONG&gt;"JType": "Medium",&lt;/STRONG&gt;&lt;BR /&gt;
    "StartTime": "0001-01-01T00:00:00Z",&lt;BR /&gt;
    "EndTime": "0001-01-01T00:00:00Z",&lt;BR /&gt;
    "isDegOnly": false,&lt;BR /&gt;
    "softId": 112892   },&lt;BR /&gt;&lt;BR /&gt;
    &lt;STRONG&gt;"commonID": "REDRF3243",&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;
    "slotStatusList": [&lt;BR /&gt;
    {&lt;BR /&gt;
      "date": "2020-03-24T00:00:00Z",&lt;BR /&gt;
      "status": [&lt;BR /&gt;
        {&lt;BR /&gt;
          "StartTime": "2020-03-24T06:30:00Z",&lt;BR /&gt;
          "EndTime": "2020-03-24T08:30:00Z",&lt;BR /&gt;
          "IsAvailable": false,&lt;BR /&gt;
          "score": 0&lt;BR /&gt;
        },&lt;BR /&gt;
        {&lt;BR /&gt;
          "StartTime": "2020-03-24T08:30:00Z",&lt;BR /&gt;
          "EndTime": "2020-03-24T10:30:00Z",&lt;BR /&gt;
          "IsAvailable": false,&lt;BR /&gt;
          "score": 0&lt;BR /&gt;
        },&lt;BR /&gt;
        {&lt;BR /&gt;
          &lt;STRONG&gt;"StartTime": "2020-03-24T10:30:00Z",&lt;BR /&gt;
          "EndTime": "2020-03-24T12:30:00Z",&lt;/STRONG&gt;&lt;BR /&gt;
          &lt;STRONG&gt;"IsAvailable": true,&lt;/STRONG&gt;&lt;BR /&gt;
          "score": 100&lt;BR /&gt;
        }&lt;BR /&gt;
      ],&lt;BR /&gt;
      "error": {&lt;BR /&gt;
        "message": ""&lt;BR /&gt;
      }&lt;BR /&gt;
    },&lt;BR /&gt;
    {&lt;BR /&gt;
      "date": "2020-03-25T00:00:00Z",&lt;BR /&gt;
      "status": [&lt;BR /&gt;
        {&lt;BR /&gt;
          "StartTime": "2020-03-25T06:30:00Z",&lt;BR /&gt;
          "EndTime": "2020-03-25T08:30:00Z",&lt;BR /&gt;
          "IsAvailable": false,&lt;BR /&gt;
          "score": 0&lt;BR /&gt;
        },&lt;BR /&gt;
        {&lt;BR /&gt;
          "StartTime": "2020-03-25T08:30:00Z",&lt;BR /&gt;
          "EndTime": "2020-03-25T10:30:00Z",&lt;BR /&gt;
          "IsAvailable": true,&lt;BR /&gt;
          "score": 92.44&lt;BR /&gt;
        },&lt;BR /&gt;
        {&lt;BR /&gt;
          "StartTime": "2020-03-25T10:30:00Z",&lt;BR /&gt;
          "EndTime": "2020-03-25T12:30:00Z",&lt;BR /&gt;
          "IsAvailable": false,&lt;BR /&gt;
          "score": 0&lt;BR /&gt;
        }&lt;BR /&gt;
      ],&lt;BR /&gt;
      "error": {&lt;BR /&gt;
        "message": ""&lt;BR /&gt;
      }&lt;BR /&gt;
    }   ] }&lt;/P&gt;

&lt;H2&gt;Payload 2&lt;/H2&gt;

&lt;HR /&gt;

&lt;P&gt;{&lt;BR /&gt;
  "Appointment": {&lt;BR /&gt;
    "Durations": 60,&lt;BR /&gt;
    "TimeSlotStartTime": "0001-01-01T00:00:00+00:00",&lt;BR /&gt;
    "TimeSlotEndTime": "0001-01-01T00:00:00+00:00",&lt;BR /&gt;
    "IsDefOnly": false,&lt;BR /&gt;
    "Job": "Medium",&lt;BR /&gt;
    "SoftId": 113291&lt;BR /&gt;
  },&lt;BR /&gt;
  &lt;STRONG&gt;"commonID": "REDRF3243",&lt;/STRONG&gt;&lt;BR /&gt;
  "GraceMinutes": 0,&lt;BR /&gt;
  "BufferMinutes": 0,&lt;BR /&gt;
  "RouteRequestList": [&lt;BR /&gt;
    {&lt;BR /&gt;
      "Date": "2020-04-02T00:00:00+00:00",&lt;BR /&gt;
      &lt;STRONG&gt;"JBID": 11936&lt;/STRONG&gt;&lt;BR /&gt;
    },&lt;BR /&gt;
    {&lt;BR /&gt;
      "Date": "2020-04-03T00:00:00+00:00",&lt;BR /&gt;
      "JBID": 11936&lt;BR /&gt;
    }&lt;BR /&gt;
  ]&lt;BR /&gt;
}&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;I need a table created like below where the Jtype, StartTime, EndTime comes from payload1 and JBID comes from Payload2 and the results needs to be merged based on the COMMONID. and there is logic where I need only the first encountered "IsAvailable": true start and end time values&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Please advise how can I achieve this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1.  JBID    JType                                START_TIME             END_TIME               COMMONID
 2.  11936    Medium                            2020-03-24T10:30:00    2020-03-24T12:30:00      REDRF3243
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Mar 2020 00:13:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490021#M194112</guid>
      <dc:creator>charan986</dc:creator>
      <dc:date>2020-03-10T00:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create a table based on values from two JSON payloads</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490022#M194113</link>
      <description>&lt;P&gt;what's index and sourcetype both?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 00:26:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490022#M194113</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-03-10T00:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create a table based on values from two JSON payloads</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490023#M194114</link>
      <description>&lt;P&gt;Hi @to4kawa, thanks for responding&lt;BR /&gt;
 these payloads are returned from the same index and source type, if thats what you're asking&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 00:28:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490023#M194114</guid>
      <dc:creator>charan986</dc:creator>
      <dc:date>2020-03-10T00:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create a table based on values from two JSON payloads</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490024#M194115</link>
      <description>&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/808272/need-to-extract-a-json-value-based-on-a-condition.html"&gt;https://answers.splunk.com/answers/808272/need-to-extract-a-json-value-based-on-a-condition.html&lt;/A&gt;&lt;BR /&gt;
How's this?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 00:44:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490024#M194115</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-03-10T00:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create a table based on values from two JSON payloads</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490025#M194116</link>
      <description>&lt;P&gt;I tried using the query from manjunathmeti but its returns empty JBID, So I wanted to post both the payloads and the complete requirement &lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 00:50:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490025#M194116</guid>
      <dc:creator>charan986</dc:creator>
      <dc:date>2020-03-10T00:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create a table based on values from two JSON payloads</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490026#M194117</link>
      <description>&lt;P&gt;I see, you can do it.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 00:57:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490026#M194117</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-03-10T00:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create a table based on values from two JSON payloads</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490027#M194118</link>
      <description>&lt;P&gt;@to4kawa  Please find my query below, this results in the table with empty JBID &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; 1.  JBID    JType                          START_TIME             END_TIME               COMMONID
  2.       Medium                        2020-03-24T10:30:00    2020-03-24T12:30:00      REDRF3243
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My search --  | spath body output=body &lt;BR /&gt;
 | spath commonID output= commonID &lt;BR /&gt;
  | eval _raw=body | spath appointment output=appointment &lt;BR /&gt;
 | eval _raw=appointment | spath JType output= JType&lt;BR /&gt;&lt;BR /&gt;
  | eval _raw=body | spath slotStatusList{} output=slotStatusList &lt;BR /&gt;
 | eval _raw=slotStatusList | spath status output=status&lt;BR /&gt;&lt;BR /&gt;
 | spath output=IsAvailable status{}.IsAvailable &lt;BR /&gt;
 | spath output=StartTime status{}.StartTime &lt;BR /&gt;
 | spath output=EndTime status{}.EndTime&lt;BR /&gt;
 | where match(IsAvailable, "true") | eval zipped=mvzip(IsAvailable,mvzip(StartTime, EndTime)) &lt;BR /&gt;
 | mvexpand zipped &lt;BR /&gt;
 | where match(zipped, "true") &lt;BR /&gt;
 | eval zipped=split(zipped, ",") &lt;BR /&gt;
 | eval IsAvailable=mvindex(zipped,0), StartTime=mvindex(zipped,1), EndTime=mvindex(zipped,2) &lt;BR /&gt;
  | spath body output=body&lt;BR /&gt;
 | eval _raw=body | spath RouteRequestList{} output=RouteRequestList &lt;BR /&gt;
 | eval _raw=RouteRequestList | spath JBID output= JBID &lt;BR /&gt;
 | stats first(*) as * by commonID&lt;BR /&gt;
 | table JBID JType StartTime EndTime commonID&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 01:10:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490027#M194118</guid>
      <dc:creator>charan986</dc:creator>
      <dc:date>2020-03-10T01:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create a table based on values from two JSON payloads</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490028#M194119</link>
      <description>&lt;P&gt;Hello @charan986,&lt;/P&gt;

&lt;P&gt;Assuming that the start and end times you want are always in the first &lt;CODE&gt;IsAvailable=true&lt;/CODE&gt; status in the slotStatusList array and the first JBID in the RouteRequestList array, lines 6 and 7 in the below query will return the table that you are looking for:&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/8519iC90035169794D145/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="{ \"appointment\": {\"appointmentId\": 0,\"key\": \"\",\"Durations\": 60,\"JType\": \"Medium\",\"StartTime\": \"0001-01-01T00:00:00Z\",\"EndTime\": \"0001-01-01T00:00:00Z\",\"isDegOnly\": false,\"softId\": 112892 },\"commonID\": \"REDRF3243\",\"slotStatusList\": [{\"date\": \"2020-03-24T00:00:00Z\",\"status\": [{\"StartTime\": \"2020-03-24T06:30:00Z\",\"EndTime\": \"2020-03-24T08:30:00Z\",\"IsAvailable\": false,\"score\": 0},{\"StartTime\": \"2020-03-24T08:30:00Z\",\"EndTime\": \"2020-03-24T10:30:00Z\",\"IsAvailable\": false,\"score\": 0},{\"StartTime\": \"2020-03-24T10:30:00Z\",\"EndTime\": \"2020-03-24T12:30:00Z\",\"IsAvailable\": true,\"score\": 100}],\"error\": {\"message\": \"\"}},{\"date\": \"2020-03-25T00:00:00Z\",\"status\": [{\"StartTime\": \"2020-03-25T06:30:00Z\",\"EndTime\": \"2020-03-25T08:30:00Z\",\"IsAvailable\": false,\"score\": 0},{\"StartTime\": \"2020-03-25T08:30:00Z\",\"EndTime\": \"2020-03-25T10:30:00Z\",\"IsAvailable\": true,\"score\": 92.44},{\"StartTime\": \"2020-03-25T10:30:00Z\",\"EndTime\": \"2020-03-25T12:30:00Z\",\"IsAvailable\": false,\"score\": 0}],\"error\": {\"message\": \"\"}} ] }
{\"Appointment\": {\"Durations\": 60,\"TimeSlotStartTime\": \"0001-01-01T00:00:00+00:00\",\"TimeSlotEndTime\": \"0001-01-01T00:00:00+00:00\",\"IsDefOnly\": false,\"Job\": \"Medium\",\"SoftId\": 113291},\"commonID\": \"REDRF3243\",\"GraceMinutes\": 0,\"BufferMinutes\": 0,\"RouteRequestList\": [{\"Date\": \"2020-04-02T00:00:00+00:00\",\"JBID\": 11936},{\"Date\": \"2020-04-03T00:00:00+00:00\",\"JBID\": 11936}]}"
| rex field=data max_match=0 "(?&amp;lt;data&amp;gt;[^\n]+)"
| mvexpand data
| eval statuses=spath(data, "slotStatusList{}.status{}"), commonID=spath(data, "commonID"), firstAvailable=mvindex(mvfilter(match(statuses, "\"IsAvailable\": true")),0), StartTime=spath(firstAvailable, "StartTime"), EndTime=spath(firstAvailable, "EndTime"), JBID=mvindex(spath(data, "RouteRequestList{}.JBID"),0), JType=spath(data, "appointment.JType")
| stats values(JBID) as JBID values(JType) as JType values(StartTime) as StartTime values(EndTime) as EndTime by commonID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Dealing with multivalued fields in json is always a pain, but can be managed a bit by managing the parent array using mvfilter and mvindex and then using spath on the resulting output, which is what I am doing with &lt;CODE&gt;statuses=spath(data, "slotStatusList{}.status{}")&lt;/CODE&gt; that creates a multivalued list of the different json payloads of the status array in the slotStatusList array and &lt;CODE&gt;firstAvailable=mvindex(mvfilter(match(statuses, "\"IsAvailable\": true")),0)&lt;/CODE&gt; which returns the first status that contains &lt;CODE&gt;"IsAvailable": true&lt;/CODE&gt;.  Let me know if anything doesn't make sense.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 13:04:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-a-table-based-on-values-from-two-JSON-payloads/m-p/490028#M194119</guid>
      <dc:creator>dmarling</dc:creator>
      <dc:date>2020-03-12T13:04:59Z</dc:date>
    </item>
  </channel>
</rss>

