<?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 do I extract fields and values from a multivalue field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-fields-and-values-from-a-multivalue-field/m-p/386788#M112867</link>
    <description>&lt;P&gt;This will split the json into the key and val values in separate rows -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval json_field = "{
\"id\": 78124,
\"uuid\": \"AWBr0ilGbvobIxfakBsC\",
\"key\": \"com.vitalityactive.va:master\",
\"name\": \"Mobile - Android - Vitality Active\",
\"scope\": \"PRJ\",
\"qualifier\": \"TRK\",
\"date\": \"2017-12-20T19:07:51+0000\",
\"creationDate\": \"2017-12-18T22:50:23+0000\",
\"lname\": \"Mobile - Android - Vitality Active\",
\"version\": \"1.0.0-rc.3\",
\"msr\": [
{
\"key\": \"ncloc\",
\"val\": 91895,
\"frmt_val\": \"91,895\"
    },
{
\"key\": \"complexity\",
\"val\": 15906,
\"frmt_val\": \"15,906\"
    },
{
\"key\": \"file_complexity\",
\"val\": 11.2,
\"frmt_val\": \"11.2\"
    },
{
\"key\": \"class_complexity\",
\"val\": 7.9,
\"frmt_val\": \"7.9\"
    },
{
\"key\": \"function_complexity\",
\"val\": 1.2,
\"frmt_val\": \"1.2\"
    },
{
\"key\": \"coverage\",
\"val\": 11.8,
\"frmt_val\": \"11.8%\"
    },
{
\"key\": \"violations\",
\"val\": 5886,
\"frmt_val\": \"5,886\"
    },
{
\"key\": \"blocker_violations\",
\"val\": 13,
\"frmt_val\": \"13\"
    },
{
\"key\": \"critical_violations\",
\"val\": 165,
\"frmt_val\": \"165\"
    },
{
\"key\": \"major_violations\",
\"val\": 3687,
\"frmt_val\": \"3,687\"
    },
{
\"key\": \"sqale_index\",
\"val\": 123465,
\"frmt_val\": \"257d\"
    }
]
}" 
| spath input=json_field output=keys path=msr{}.key 
| spath input=json_field output=vals path=msr{}.val 
| fields keys, vals 
| eval x=mvzip(keys,vals) 
| mvexpand x 
| eval x = split(x,",") 
| eval key=mvindex(x,0) 
| eval val=mvindex(x,1) 
| table key, val
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You will need to tweak the above to use the raw event rather than the generated eval field.&lt;/P&gt;</description>
    <pubDate>Thu, 20 Sep 2018 16:37:39 GMT</pubDate>
    <dc:creator>msivill_splunk</dc:creator>
    <dc:date>2018-09-20T16:37:39Z</dc:date>
    <item>
      <title>How do I extract fields and values from a multivalue field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-fields-and-values-from-a-multivalue-field/m-p/386786#M112865</link>
      <description>&lt;P&gt;this is my JSON object i am getting as an event&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
  "id": 78124,
  "uuid": "AWBr0ilGbvobIxfakBsC",
  "key": "com.vitalityactive.va:master",
  "name": "Mobile - Android - Vitality Active",
  "scope": "PRJ",
  "qualifier": "TRK",
  "date": "2017-12-20T19:07:51+0000",
  "creationDate": "2017-12-18T22:50:23+0000",
  "lname": "Mobile - Android - Vitality Active",
  "version": "1.0.0-rc.3",
  "msr": [
    {
      "key": "ncloc",
      "val": 91895,
      "frmt_val": "91,895"
    },
    {
      "key": "complexity",
      "val": 15906,
      "frmt_val": "15,906"
    },
    {
      "key": "file_complexity",
      "val": 11.2,
      "frmt_val": "11.2"
    },
    {
      "key": "class_complexity",
      "val": 7.9,
      "frmt_val": "7.9"
    },
    {
      "key": "function_complexity",
      "val": 1.2,
      "frmt_val": "1.2"
    },
    {
      "key": "coverage",
      "val": 11.8,
      "frmt_val": "11.8%"
    },
    {
      "key": "violations",
      "val": 5886,
      "frmt_val": "5,886"
    },
    {
      "key": "blocker_violations",
      "val": 13,
      "frmt_val": "13"
    },
    {
      "key": "critical_violations",
      "val": 165,
      "frmt_val": "165"
    },
    {
      "key": "major_violations",
      "val": 3687,
      "frmt_val": "3,687"
    },
    {
      "key": "sqale_index",
      "val": 123465,
      "frmt_val": "257d"
    }
  ]
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to extract all the keys and values inside "msr". &lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 15:26:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-fields-and-values-from-a-multivalue-field/m-p/386786#M112865</guid>
      <dc:creator>sivaranjiniG</dc:creator>
      <dc:date>2018-09-20T15:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract fields and values from a multivalue field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-fields-and-values-from-a-multivalue-field/m-p/386787#M112866</link>
      <description>&lt;P&gt;@sivaranjiniG&lt;/P&gt;

&lt;P&gt;Can you please try following search?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH  | rename msr{}.* as * 
| eval tempField=mvzip(key,val) 
| stats count by _time id tempField
| eval key = mvindex(split(tempField,","),0), val= mvindex(split(tempField,","),1)  
| table key val
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;My Sample Search&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{
\"id\": 78124,
\"uuid\": \"AWBr0ilGbvobIxfakBsC\",
\"key\": \"com.vitalityactive.va:master\",
\"name\": \"Mobile - Android - Vitality Active\",
\"scope\": \"PRJ\",
\"qualifier\": \"TRK\",
\"date\": \"2017-12-20T19:07:51+0000\",
\"creationDate\": \"2017-12-18T22:50:23+0000\",
\"lname\": \"Mobile - Android - Vitality Active\",
\"version\": \"1.0.0-rc.3\",
\"msr\": [
{
\"key\": \"ncloc\",
\"val\": 91895,
\"frmt_val\": \"91,895\"
    },
{
\"key\": \"complexity\",
\"val\": 15906,
\"frmt_val\": \"15,906\"
    },
{
\"key\": \"file_complexity\",
\"val\": 11.2,
\"frmt_val\": \"11.2\"
    },
{
\"key\": \"class_complexity\",
\"val\": 7.9,
\"frmt_val\": \"7.9\"
    },
{
\"key\": \"function_complexity\",
\"val\": 1.2,
\"frmt_val\": \"1.2\"
    },
{
\"key\": \"coverage\",
\"val\": 11.8,
\"frmt_val\": \"11.8%\"
    },
{
\"key\": \"violations\",
\"val\": 5886,
\"frmt_val\": \"5,886\"
    },
{
\"key\": \"blocker_violations\",
\"val\": 13,
\"frmt_val\": \"13\"
    },
{
\"key\": \"critical_violations\",
\"val\": 165,
\"frmt_val\": \"165\"
    },
{
\"key\": \"major_violations\",
\"val\": 3687,
\"frmt_val\": \"3,687\"
    },
{
\"key\": \"sqale_index\",
\"val\": 123465,
\"frmt_val\": \"257d\"
    }
]
}" 
| kv 
| rename msr{}.* as * 
| eval tempField=mvzip(key,val) 
| stats count by _time id tempField
| eval key = mvindex(split(tempField,","),0), val= mvindex(split(tempField,","),1)  
| table key val
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 16:36:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-fields-and-values-from-a-multivalue-field/m-p/386787#M112866</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2018-09-20T16:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract fields and values from a multivalue field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-fields-and-values-from-a-multivalue-field/m-p/386788#M112867</link>
      <description>&lt;P&gt;This will split the json into the key and val values in separate rows -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval json_field = "{
\"id\": 78124,
\"uuid\": \"AWBr0ilGbvobIxfakBsC\",
\"key\": \"com.vitalityactive.va:master\",
\"name\": \"Mobile - Android - Vitality Active\",
\"scope\": \"PRJ\",
\"qualifier\": \"TRK\",
\"date\": \"2017-12-20T19:07:51+0000\",
\"creationDate\": \"2017-12-18T22:50:23+0000\",
\"lname\": \"Mobile - Android - Vitality Active\",
\"version\": \"1.0.0-rc.3\",
\"msr\": [
{
\"key\": \"ncloc\",
\"val\": 91895,
\"frmt_val\": \"91,895\"
    },
{
\"key\": \"complexity\",
\"val\": 15906,
\"frmt_val\": \"15,906\"
    },
{
\"key\": \"file_complexity\",
\"val\": 11.2,
\"frmt_val\": \"11.2\"
    },
{
\"key\": \"class_complexity\",
\"val\": 7.9,
\"frmt_val\": \"7.9\"
    },
{
\"key\": \"function_complexity\",
\"val\": 1.2,
\"frmt_val\": \"1.2\"
    },
{
\"key\": \"coverage\",
\"val\": 11.8,
\"frmt_val\": \"11.8%\"
    },
{
\"key\": \"violations\",
\"val\": 5886,
\"frmt_val\": \"5,886\"
    },
{
\"key\": \"blocker_violations\",
\"val\": 13,
\"frmt_val\": \"13\"
    },
{
\"key\": \"critical_violations\",
\"val\": 165,
\"frmt_val\": \"165\"
    },
{
\"key\": \"major_violations\",
\"val\": 3687,
\"frmt_val\": \"3,687\"
    },
{
\"key\": \"sqale_index\",
\"val\": 123465,
\"frmt_val\": \"257d\"
    }
]
}" 
| spath input=json_field output=keys path=msr{}.key 
| spath input=json_field output=vals path=msr{}.val 
| fields keys, vals 
| eval x=mvzip(keys,vals) 
| mvexpand x 
| eval x = split(x,",") 
| eval key=mvindex(x,0) 
| eval val=mvindex(x,1) 
| table key, val
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You will need to tweak the above to use the raw event rather than the generated eval field.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 16:37:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-fields-and-values-from-a-multivalue-field/m-p/386788#M112867</guid>
      <dc:creator>msivill_splunk</dc:creator>
      <dc:date>2018-09-20T16:37:39Z</dc:date>
    </item>
  </channel>
</rss>

