<?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 get specific value from key/value array to form table? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-specific-value-from-key-value-array-to-form-table/m-p/629843#M218818</link>
    <description>&lt;P&gt;Another way to do it is to extract and expand the collection&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath
| spath msg.details{} output=details
| mvexpand details
| spath input=details
| where keyName="trace"
| table msg.transId msg.status keyValue&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 07 Feb 2023 07:47:48 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2023-02-07T07:47:48Z</dc:date>
    <item>
      <title>How to get specific value from key/value array to form table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-specific-value-from-key-value-array-to-form-table/m-p/629810#M218802</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I don't have much experience with Splunk. My JSON payload looks like as shown below. The msg.details array can have any number key/value pairs in any order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{
  "appName": "TestApp",
  "eventType": "Response",
  "msg": {
    "transId": "Trans1234",
    "status": "Success",
    "client": "clientXyz",
    "responseTime": 1650,
    "details": [
      {
        "keyName": "rtt",
        "keyValue": 2778
      },
      {
        "keyName": "trace",
        "keyValue": 97007839130680
      }
    ],
    "url": "/v1/test"
  }
}&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;I am trying to write a query and form a table as shown below. I am interested in displaying only the keyValue of keyName:trace in the table. Any help is appreciated. Thanks.&lt;/P&gt;
&lt;P&gt;index=* appName="TestApp" msg.url="/v1/test" | table msg.transId, msg.status, msg.details[keyName="trace"].keyValue&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;msg.transId&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;msg.status&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;msg.details[keyName="trace"].keyValue&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;Trans1234&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;Success&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;97007839130680&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;Trans7890&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;ERROR&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;29411645500355&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 02:10:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-specific-value-from-key-value-array-to-form-table/m-p/629810#M218802</guid>
      <dc:creator>btsr</dc:creator>
      <dc:date>2023-02-07T02:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: Get specific value from key/value array to form table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-specific-value-from-key-value-array-to-form-table/m-p/629815#M218804</link>
      <description>&lt;P&gt;Splunk doesn't recognize square brackets as denoting a JSON array; they identify a subsearch.&lt;/P&gt;&lt;P&gt;We also can't reference a JSON array element by name.&amp;nbsp; Perhaps some day...&lt;/P&gt;&lt;P&gt;Here's a run-anywhere query showing one way to accomplish the task.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw="{
  \"appName\": \"TestApp\",
  \"eventType\": \"Response\",
  \"msg\": {
    \"transId\": \"Trans1234\",
    \"status\": \"Success\",
    \"client\": \"clientXyz\",
    \"responseTime\": 1650,
    \"details\": [
      {
        \"keyName\": \"rtt\",
        \"keyValue\": 2778
      },
      {
        \"keyName\": \"trace\",
        \"keyValue\": 97007839130680
      }
    ],
    \"url\": \"/v1/test\"
  }
}" | spath 
``` Everything above sets up test data.  Delete IRL. ```
``` Combine keyName and keyValue so we can work with them as a pair. ```
| eval foo=mvzip('msg.details{}.keyName','msg.details{}.keyValue')
``` Locate "trace" keys ```
| eval foo=mvindex(foo,mvfind(foo,"trace"))
``` Break up the keyName/keyValue pair for display ```
| eval foo=split(foo,",")
| eval keyName=mvindex(foo,0), keyValue=mvindex(foo,1)
| table msg.transId, msg.status, keyName, keyValue&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 07 Feb 2023 01:19:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-specific-value-from-key-value-array-to-form-table/m-p/629815#M218804</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-02-07T01:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to get specific value from key/value array to form table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-specific-value-from-key-value-array-to-form-table/m-p/629843#M218818</link>
      <description>&lt;P&gt;Another way to do it is to extract and expand the collection&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath
| spath msg.details{} output=details
| mvexpand details
| spath input=details
| where keyName="trace"
| table msg.transId msg.status keyValue&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 07 Feb 2023 07:47:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-specific-value-from-key-value-array-to-form-table/m-p/629843#M218818</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-02-07T07:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to get specific value from key/value array to form table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-specific-value-from-key-value-array-to-form-table/m-p/629979#M218854</link>
      <description>&lt;P&gt;This saved my day! Thank you &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 19:49:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-specific-value-from-key-value-array-to-form-table/m-p/629979#M218854</guid>
      <dc:creator>btsr</dc:creator>
      <dc:date>2023-02-07T19:49:38Z</dc:date>
    </item>
  </channel>
</rss>

