<?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 compute size of array field in JSON using spath in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447353#M77801</link>
    <description>&lt;P&gt;That is because the arrayField in multivalued , try this:&lt;BR /&gt;
    | makeresults | eval raw="{\"arrayField\":[{\"a\":\"b\"}, {\"c\":\"d\"}], \"objField\":{\"e\":\"f\"}}" | spath input=raw path=objField | eval objFieldSize = len(objField)| spath input=raw path=arrayField{} output=arrayField |  table objFieldSize, objField, arraySize,  arrayField&lt;BR /&gt;
    | mvexpand arrayField&lt;BR /&gt;
    | eval arraySize=len(arrayField)&lt;BR /&gt;
    | mvcombine arrayField&lt;/P&gt;</description>
    <pubDate>Sun, 05 May 2019 06:13:04 GMT</pubDate>
    <dc:creator>Sukisen1981</dc:creator>
    <dc:date>2019-05-05T06:13:04Z</dc:date>
    <item>
      <title>How to compute size of array field in JSON using spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447352#M77800</link>
      <description>&lt;P&gt;I want to calculate the raw size of an array field in JSON. &lt;CODE&gt;len()&lt;/CODE&gt; command works fine to calculate size of JSON object field, but &lt;CODE&gt;len()&lt;/CODE&gt; command doesn't work for array field. Here is the query e.g:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval raw="{\"arrayField\":[{\"a\":\"b\"}, {\"c\":\"d\"}], \"objField\":{\"e\":\"f\"}}" | spath input=raw path=objField | eval objFieldSize = len(objField)| spath input=raw path=arrayField{} output=arrayField | eval arraySize=len(arrayField) | table objFieldSize, objField, arraySize,  arrayField
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It produces output:&lt;/P&gt;

&lt;P&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/7019iEA4A07BB81CF32E8/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;P&gt;It shows the correct value for objFieldSize, but arrayFieldSize is empty. Am I missing something..? How can I compute arrayFieldSize corectly?&lt;/P&gt;</description>
      <pubDate>Sun, 05 May 2019 03:19:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447352#M77800</guid>
      <dc:creator>relango</dc:creator>
      <dc:date>2019-05-05T03:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute size of array field in JSON using spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447353#M77801</link>
      <description>&lt;P&gt;That is because the arrayField in multivalued , try this:&lt;BR /&gt;
    | makeresults | eval raw="{\"arrayField\":[{\"a\":\"b\"}, {\"c\":\"d\"}], \"objField\":{\"e\":\"f\"}}" | spath input=raw path=objField | eval objFieldSize = len(objField)| spath input=raw path=arrayField{} output=arrayField |  table objFieldSize, objField, arraySize,  arrayField&lt;BR /&gt;
    | mvexpand arrayField&lt;BR /&gt;
    | eval arraySize=len(arrayField)&lt;BR /&gt;
    | mvcombine arrayField&lt;/P&gt;</description>
      <pubDate>Sun, 05 May 2019 06:13:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447353#M77801</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-05-05T06:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute size of array field in JSON using spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447354#M77802</link>
      <description>&lt;P&gt;@relango try the &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/MultivalueEvalFunctions#mvcount.28MVFIELD.29"&gt;mvcount() evaluation function&lt;/A&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval arraySize=mvcount(arrayField)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 May 2019 13:44:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447354#M77802</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-05-05T13:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute size of array field in JSON using spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447355#M77803</link>
      <description>&lt;P&gt;Thanks, Sukisen. The query works but now computed arraySize value is for the only first element in the array and not for the complete array.&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 14:42:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447355#M77803</guid>
      <dc:creator>relango</dc:creator>
      <dc:date>2019-05-06T14:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute size of array field in JSON using spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447356#M77804</link>
      <description>&lt;P&gt;Using &lt;CODE&gt;mvjoin&lt;/CODE&gt; did the trick. Here is the working query for anyone looking for answer.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval raw="{\"arrayField\":[{\"a\":\"b\"}, {\"c\":\"d\"}], \"objField\":{\"e\":\"f\"}}" | spath input=raw path=objField | eval objFieldSize = len(objField)| spath input=raw path=arrayField{} output=arrayField | eval arraySize=len(mvjoin(arrayField,"")) | table objFieldSize, objField, arraySize,  arrayField
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 May 2019 14:48:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447356#M77804</guid>
      <dc:creator>relango</dc:creator>
      <dc:date>2019-05-06T14:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute size of array field in JSON using spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447357#M77805</link>
      <description>&lt;P&gt;@relango if you want to count the multi-valued field values and keep the field as multi-valued, you should use &lt;CODE&gt;mvcount()&lt;/CODE&gt; instead of mvjoin which makes it is single value field.&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 15:12:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447357#M77805</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-05-06T15:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute size of array field in JSON using spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447358#M77806</link>
      <description>&lt;P&gt;@relango  - Glad to see you figured this out yourself, i knew a few permutations of the different mv functions will sort this out, upvoted your comment and please accept your own answer as it resolved the issue.&lt;BR /&gt;
Many apologies , I was stuck with office work and could not get back to you earlier on this, but then again I did not need to since you figured it out yourself &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 08:29:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447358#M77806</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-05-11T08:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute size of array field in JSON using spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447359#M77807</link>
      <description>&lt;P&gt;Sure, Thanks for your hint which helped me figure it out.&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 20:01:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-size-of-array-field-in-JSON-using-spath/m-p/447359#M77807</guid>
      <dc:creator>relango</dc:creator>
      <dc:date>2019-05-11T20:01:15Z</dc:date>
    </item>
  </channel>
</rss>

