<?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 parse json array and rename the values? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-json-array-and-rename-the-values/m-p/294864#M56026</link>
    <description>&lt;P&gt;@mkamal18, please try the following run anywhere search. Since you are not worried about dsnames and dstypes JSON nodes, I have taken them out while creating test data as per sample provided. This implies actual JSON field name for &lt;CODE&gt;values&lt;/CODE&gt;, on using &lt;CODE&gt;spath&lt;/CODE&gt; command will change from the one used in this example.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="{
    \"host\": \"test\", 
    \"interval\": 60 ,
    \"plugin\": \"snmp\", 
    \"plugin_instance\": {
        \"time\": \"1510070934.341\", 
        \"type\": \"ps_count\", 
        \"type_instance\": \"fval3-cp-23800-1_vs30\", 
        \"values\": [45,0]}}"
|  spath
|  rename "plugin_instance.values{}" AS "values"
|  eval name=mvindex(values,0)
|  eval value=mvindex(values,1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can pipe &lt;CODE&gt;spath&lt;/CODE&gt; command to your raw data to get JSON fields extracted. You will notice the &lt;CODE&gt;*values{}&lt;/CODE&gt; field will be multi-valued array. You would need to rename according to its name to simplified name such as &lt;CODE&gt;values&lt;/CODE&gt;. Finally use the &lt;CODE&gt;mvindex()&lt;/CODE&gt; evaluation function to pull values at 0 and 1 index.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;YourBaseSearch&amp;gt;
| spath
|  rename "plugin_instance.values{}" AS "values"
|  eval name=mvindex(values,0)
|  eval value=mvindex(values,1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Please change the rename command as per actual original field name for &lt;CODE&gt;*values{}&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Nov 2017 16:27:48 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-11-23T16:27:48Z</dc:date>
    <item>
      <title>How to parse json array and rename the values?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-json-array-and-rename-the-values/m-p/294862#M56024</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I would like to parse the array called &lt;STRONG&gt;values&lt;/STRONG&gt; that contains 45 and 0 &lt;BR /&gt;
I want to rename them then 45 as name and 0 as value&lt;/P&gt;

&lt;P&gt;{   [-] &lt;BR /&gt;
     dsnames:   [   [+] &lt;BR /&gt;
    ]&lt;BR /&gt;&lt;BR /&gt;
     dstypes:   [   [+] &lt;BR /&gt;
    ]&lt;BR /&gt;&lt;BR /&gt;
     host:   test&lt;BR /&gt;&lt;BR /&gt;
     interval:   60 &lt;BR /&gt;
     plugin:     snmp&lt;BR /&gt;&lt;BR /&gt;
     plugin_instance:&lt;BR /&gt;&lt;BR /&gt;
     time:   1510070934.341 &lt;BR /&gt;
     type:   ps_count&lt;BR /&gt;&lt;BR /&gt;
     type_instance:  fval3-cp-23800-1_vs30&lt;BR /&gt;&lt;BR /&gt;
     &lt;STRONG&gt;values:  [   [-] &lt;BR /&gt;
         45 &lt;BR /&gt;
         0&lt;BR /&gt;&lt;BR /&gt;
    ]&lt;/STRONG&gt; &lt;BR /&gt;
}&lt;/P&gt;

&lt;P&gt;Can you help me please?&lt;/P&gt;

&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:52:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-json-array-and-rename-the-values/m-p/294862#M56024</guid>
      <dc:creator>mkamal18</dc:creator>
      <dc:date>2020-09-29T16:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse json array and rename the values?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-json-array-and-rename-the-values/m-p/294863#M56025</link>
      <description>&lt;P&gt;Hi @mkamal18,&lt;/P&gt;

&lt;P&gt;Use &lt;CODE&gt;values{}&lt;/CODE&gt; to access &lt;STRONG&gt;values&lt;/STRONG&gt; field.&lt;/P&gt;

&lt;P&gt;Please check my sample search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"values\": [\"45\",\"0\"] }" 
| spath  
| rename values{} as values
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Happy Splunking&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 16:23:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-json-array-and-rename-the-values/m-p/294863#M56025</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-11-23T16:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse json array and rename the values?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-json-array-and-rename-the-values/m-p/294864#M56026</link>
      <description>&lt;P&gt;@mkamal18, please try the following run anywhere search. Since you are not worried about dsnames and dstypes JSON nodes, I have taken them out while creating test data as per sample provided. This implies actual JSON field name for &lt;CODE&gt;values&lt;/CODE&gt;, on using &lt;CODE&gt;spath&lt;/CODE&gt; command will change from the one used in this example.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="{
    \"host\": \"test\", 
    \"interval\": 60 ,
    \"plugin\": \"snmp\", 
    \"plugin_instance\": {
        \"time\": \"1510070934.341\", 
        \"type\": \"ps_count\", 
        \"type_instance\": \"fval3-cp-23800-1_vs30\", 
        \"values\": [45,0]}}"
|  spath
|  rename "plugin_instance.values{}" AS "values"
|  eval name=mvindex(values,0)
|  eval value=mvindex(values,1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can pipe &lt;CODE&gt;spath&lt;/CODE&gt; command to your raw data to get JSON fields extracted. You will notice the &lt;CODE&gt;*values{}&lt;/CODE&gt; field will be multi-valued array. You would need to rename according to its name to simplified name such as &lt;CODE&gt;values&lt;/CODE&gt;. Finally use the &lt;CODE&gt;mvindex()&lt;/CODE&gt; evaluation function to pull values at 0 and 1 index.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;YourBaseSearch&amp;gt;
| spath
|  rename "plugin_instance.values{}" AS "values"
|  eval name=mvindex(values,0)
|  eval value=mvindex(values,1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Please change the rename command as per actual original field name for &lt;CODE&gt;*values{}&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 16:27:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-json-array-and-rename-the-values/m-p/294864#M56026</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-23T16:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse json array and rename the values?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-json-array-and-rename-the-values/m-p/294865#M56027</link>
      <description>&lt;P&gt;Perfect it works,  Thanks man!! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 16:34:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-json-array-and-rename-the-values/m-p/294865#M56027</guid>
      <dc:creator>mkamal18</dc:creator>
      <dc:date>2017-11-23T16:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse json array and rename the values?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-json-array-and-rename-the-values/m-p/294866#M56028</link>
      <description>&lt;P&gt;Anytime! Do think of us in case you need further help with your Splunk queries &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 04:03:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-json-array-and-rename-the-values/m-p/294866#M56028</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-24T04:03:44Z</dc:date>
    </item>
  </channel>
</rss>

