<?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 create a dynamic loop through a JSON array that looks for a trigger in any element in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-dynamic-loop-through-a-JSON-array-that-looks-for/m-p/486596#M31890</link>
    <description>&lt;P&gt;Here is a solution without using mvzip:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="{ \"storeID\":\"000\",
  \"activeStatus\":\"Active\",
  \"location\":{
  \"addressLine1\":\"4300 Store Rd\",
  \"city\":\"Atlanta\",
  \"zip\":\"99999\",
  \"state\":\"GA\",
  \"mainNumber\":\"9999999999\" },
  \"capabilities\":[
  {\"name\":\"Sales\", \"startDateUtc\":\"2019-11-10T07:00:00\"},
  {\"name\":\"Accounting\", \"startDateUtc\":\"2019-12-05T07:00:00\"},
  {\"name\":\"Shipping\", \"startDateUtc\":\"2019-10-23T07:00:00\"},
  {\"name\":\"Executive\", \"startDateUtc\":\"2019-10-23T07:00:00\"},
  {\"name\":\"Delivery\", \"startDateUtc\":\"2019-10-23T07:00:00\"}
]}"
| spath output=capabilities path=capabilities{}
| mvexpand capabilities
| spath input=capabilities
| eval today=strftime(now(), "%Y-%m-%d")
| where match(startDateUtc, today)
| table name, startDateUtc
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 05 Dec 2019 13:56:41 GMT</pubDate>
    <dc:creator>vmacedo</dc:creator>
    <dc:date>2019-12-05T13:56:41Z</dc:date>
    <item>
      <title>How to create a dynamic loop through a JSON array that looks for a trigger in any element</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-dynamic-loop-through-a-JSON-array-that-looks-for/m-p/486594#M31888</link>
      <description>&lt;P&gt;Data example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; "storeID":"000",
    "activeStatus":"Active",
    "location":{ 
        "addressLine1":"4300 Store Rd"
        "city":"Atlanta",
        "zip":"99999"
        "state":"GA",
        "mainNumber":"9999999999"
    },
    "capabilities":[ 
        { 
            "name":"Sales"
            "startDateUtc":"2019-11-10T07:00:00"
        },
        { 
            "name":"Accounting"
            "startDateUtc":"2019-10-23T07:00:00"
        },
        { 
            "name":"Shipping"
            "startDateUtc":"2019-10-23T07:00:00"
        },
        { 
            "name":"Executive"
            "startDateUtc":"2019-10-23T07:00:00"
        },
        { 
            "name":"Delivery",
            "startDateUtc":"2019-10-23T07:00:00"
        }
    ]
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Fairly new to Splunk and I am looking for a way to loop through "capabilities" looking for today's date.  If there is a match from any element it returns the "name" associated with it. &lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 19:05:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-dynamic-loop-through-a-JSON-array-that-looks-for/m-p/486594#M31888</guid>
      <dc:creator>splunkr00kie</dc:creator>
      <dc:date>2019-11-18T19:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a dynamic loop through a JSON array that looks for a trigger in any element</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-dynamic-loop-through-a-JSON-array-that-looks-for/m-p/486595#M31889</link>
      <description>&lt;P&gt;Hey! JSON arrays are rather notorious to work with - Splunk treats them like multi-value fields even though they look like they're separate (or at least from your event I understand that to be the case). Based on my understanding of your use case, you need to tie the individual events together, separate them out, filter to where startDateUtc is today, and then table the name. Try running this search and letting me know if its helpful, I would suggest going line by line and also adding various &lt;CODE&gt;| table {fieldName}&lt;/CODE&gt;, where fieldName is the field you care about, to understand what I'm doing:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;your_base_search&lt;BR /&gt;
| eval name_zip_startDateUtc=mvzip(name,startDateUtc)&lt;BR /&gt;
| mvexpand name_zip_startDateUtc&lt;BR /&gt;
| eval name_zip_startDateUtc=split(name_zip_startDateUtc,",")&lt;BR /&gt;
| eval name=mvindex(name_zip_startDateUtc,0)&lt;BR /&gt;
| eval startDateUtc=mvindex(name_zip_startDateUtc,1)&lt;BR /&gt;
| eval today=strftime(now(), "%Y-%m-%d")&lt;BR /&gt;
| rex field=startDateUtc "(?.*)T.*"&lt;BR /&gt;
| where Date=today&lt;BR /&gt;
| table name&lt;BR /&gt;
&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 23:36:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-dynamic-loop-through-a-JSON-array-that-looks-for/m-p/486595#M31889</guid>
      <dc:creator>aberkow</dc:creator>
      <dc:date>2019-11-18T23:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a dynamic loop through a JSON array that looks for a trigger in any element</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-dynamic-loop-through-a-JSON-array-that-looks-for/m-p/486596#M31890</link>
      <description>&lt;P&gt;Here is a solution without using mvzip:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="{ \"storeID\":\"000\",
  \"activeStatus\":\"Active\",
  \"location\":{
  \"addressLine1\":\"4300 Store Rd\",
  \"city\":\"Atlanta\",
  \"zip\":\"99999\",
  \"state\":\"GA\",
  \"mainNumber\":\"9999999999\" },
  \"capabilities\":[
  {\"name\":\"Sales\", \"startDateUtc\":\"2019-11-10T07:00:00\"},
  {\"name\":\"Accounting\", \"startDateUtc\":\"2019-12-05T07:00:00\"},
  {\"name\":\"Shipping\", \"startDateUtc\":\"2019-10-23T07:00:00\"},
  {\"name\":\"Executive\", \"startDateUtc\":\"2019-10-23T07:00:00\"},
  {\"name\":\"Delivery\", \"startDateUtc\":\"2019-10-23T07:00:00\"}
]}"
| spath output=capabilities path=capabilities{}
| mvexpand capabilities
| spath input=capabilities
| eval today=strftime(now(), "%Y-%m-%d")
| where match(startDateUtc, today)
| table name, startDateUtc
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Dec 2019 13:56:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-dynamic-loop-through-a-JSON-array-that-looks-for/m-p/486596#M31890</guid>
      <dc:creator>vmacedo</dc:creator>
      <dc:date>2019-12-05T13:56:41Z</dc:date>
    </item>
  </channel>
</rss>

