<?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: How to extract value from log events with type as json object or json array?? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-value-from-log-events-with-type-as-json-object-or/m-p/559206#M158879</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/236323"&gt;@bhavika100&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you try this, I would have done this much cleaner however your json payload is so dynamic with arrays and field names change.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval req=replace(json_extract(_raw, "message.request"),"body","") 
| eval res=replace(json_extract(_raw, "message.response"),"body","") 
| eval httpdetails="\n"+req+"\n-----------------Response---------------\n"+res, httpdetails = split(httpdetails,"\n") 
| eval details=if(isnotnull(httpdetails), httpdetails, details) 
| table details&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;You can further truncate {" if you want much cleaner, response does come-up with this SPL.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="venkatasri_0-1626152672194.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/15056i80C515FC0C50DBF1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="venkatasri_0-1626152672194.png" alt="venkatasri_0-1626152672194.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;An upvote would be appreciated and Accept Solution if this reply helps!&lt;/P&gt;</description>
    <pubDate>Tue, 13 Jul 2021 05:05:42 GMT</pubDate>
    <dc:creator>venkatasri</dc:creator>
    <dc:date>2021-07-13T05:05:42Z</dc:date>
    <item>
      <title>How to extract value from log events with type as json object or json array??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-value-from-log-events-with-type-as-json-object-or/m-p/559178#M158867</link>
      <description>&lt;P&gt;Our event log has request and response. Request and response body can either be a json object or json array. I need to extract resquest.body and response.body to construct a field "httpdetails" which is a string . How can i achieve this using single spath function.&lt;/P&gt;&lt;P&gt;example of log events :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "message": {
    "request": {
      "body": {}
    },
    "response": {
      "body": [
        {
          "id": "85118db6-2d5c-6bb0-ff67-5bc9ef5d4a1f",
          "createdon": "2021-07-08T00:37:02.512Z"
        }
      ]
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "message": {
    "request": {
      "body": {
        "$limitafter": "2021-07-08T20:08:29.983Z"
      }
    },
    "response": {
      "statuscode": 200,
      "body": {
        "count": "22"
      }
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Splunk query :&lt;/P&gt;&lt;P class="p1"&gt;| spath output=response_data message.response.body | spath output=request_data message.request.body | eval request_data=if(isnull(request_data) , NULL , request_data) | eval response_data=if(isnull(response_data),&amp;nbsp; NULL, response_data) | eval httpdetails="\n"+request_data+"\n-----------------Response---------------\n"+response_data, httpdetails = split(httpdetails,"\n")&amp;nbsp;| eval details=if(isnotnull(httpdetails), httpdetails, details)&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;After running this query "httpdetails" is shown below. Here response_data for first log event is coming as NULL instead of object array. How can I fix this??&lt;/P&gt;&lt;P class="p1"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2021-07-12 at 3.00.50 PM.png" style="width: 852px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/15051i0922E2003C694A6C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2021-07-12 at 3.00.50 PM.png" alt="Screen Shot 2021-07-12 at 3.00.50 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 22:12:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-value-from-log-events-with-type-as-json-object-or/m-p/559178#M158867</guid>
      <dc:creator>bhavika100</dc:creator>
      <dc:date>2021-07-12T22:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract value from log events with type as json object or json array??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-value-from-log-events-with-type-as-json-object-or/m-p/559206#M158879</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/236323"&gt;@bhavika100&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you try this, I would have done this much cleaner however your json payload is so dynamic with arrays and field names change.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval req=replace(json_extract(_raw, "message.request"),"body","") 
| eval res=replace(json_extract(_raw, "message.response"),"body","") 
| eval httpdetails="\n"+req+"\n-----------------Response---------------\n"+res, httpdetails = split(httpdetails,"\n") 
| eval details=if(isnotnull(httpdetails), httpdetails, details) 
| table details&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;You can further truncate {" if you want much cleaner, response does come-up with this SPL.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="venkatasri_0-1626152672194.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/15056i80C515FC0C50DBF1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="venkatasri_0-1626152672194.png" alt="venkatasri_0-1626152672194.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;An upvote would be appreciated and Accept Solution if this reply helps!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 05:05:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-value-from-log-events-with-type-as-json-object-or/m-p/559206#M158879</guid>
      <dc:creator>venkatasri</dc:creator>
      <dc:date>2021-07-13T05:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract value from log events with type as json object or json array??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-value-from-log-events-with-type-as-json-object-or/m-p/559724#M159020</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/163730"&gt;@venkatasri&lt;/a&gt;&amp;nbsp;Thanks for the quick resposne. This solution works fine for the above logs. I tried to implement the same in my query but fails when either request or response body is null. Log event is as below.&lt;/P&gt;&lt;P&gt;log event:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "message": {
    "request": {
      "body": null
    },
    "response": {
      "statuscode": 200,
      "body": {
        "id": "e4214ec1-3d16-6083-ec11-beb01188ddaf"
      }
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;details is coming as empty for this log event.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 00:45:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-value-from-log-events-with-type-as-json-object-or/m-p/559724#M159020</guid>
      <dc:creator>bhavika100</dc:creator>
      <dc:date>2021-07-16T00:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract value from log events with type as json object or json array??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-value-from-log-events-with-type-as-json-object-or/m-p/559727#M159022</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/236323"&gt;@bhavika100&lt;/a&gt;&amp;nbsp;Sure thing let me find out.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 01:01:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-value-from-log-events-with-type-as-json-object-or/m-p/559727#M159022</guid>
      <dc:creator>venkatasri</dc:creator>
      <dc:date>2021-07-16T01:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract value from log events with type as json object or json array??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-value-from-log-events-with-type-as-json-object-or/m-p/559729#M159023</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/236323"&gt;@bhavika100&lt;/a&gt;&amp;nbsp;I have tried your new payload there message.request.body = null hence same has been showing in output as null below and response is fine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="venkatasri_0-1626397674062.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/15118i448322DEFF4EA297/image-size/medium?v=v2&amp;amp;px=400" role="button" title="venkatasri_0-1626397674062.png" alt="venkatasri_0-1626397674062.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;An upvote would be appreciated if this reply helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 01:08:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-value-from-log-events-with-type-as-json-object-or/m-p/559729#M159023</guid>
      <dc:creator>venkatasri</dc:creator>
      <dc:date>2021-07-16T01:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract value from log events with type as json object or json array??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-value-from-log-events-with-type-as-json-object-or/m-p/559825#M159065</link>
      <description>&lt;P&gt;This works!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 15:10:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-value-from-log-events-with-type-as-json-object-or/m-p/559825#M159065</guid>
      <dc:creator>bhavika100</dc:creator>
      <dc:date>2021-07-16T15:10:52Z</dc:date>
    </item>
  </channel>
</rss>

