<?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 How handle JSON-Event with associative Array in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-handle-JSON-Event-with-associative-Array/m-p/432708#M123645</link>
    <description>&lt;P&gt;Hi, &lt;BR /&gt;
i need a special result, but i dont know how to iterate over an associative array. &lt;/P&gt;

&lt;P&gt;Here is this JSON-Events: &lt;/P&gt;

&lt;P&gt;Event 1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
"created": "28\/May\/2018:06:24:00 +0200",
"response": {           
            "products": {
                "1": {
                    "id": 10,                       
                    "price": 120                        
                },
                "2": {
                    "id": 20,                       
                    "price": 65                     
                },
                "3": {
                    "id": 30,                       
                    "price": 80 
                }
            }
        }       
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Event 2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
"created": "30\/May\/2018:08:10:00 +0200",
"response": {           
            "products": {
                "1": {
                    "id": 40,                       
                    "price": 120                        
                },
                "2": {
                    "id": 50,                       
                    "price": 65                     
                }
            }
        }       
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And i need the folowing result: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ID      Price
-------------------
10      120
20      65
...      
50      65
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any idea? &lt;BR /&gt;
Many thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 31 May 2018 10:29:51 GMT</pubDate>
    <dc:creator>Roger_FB</dc:creator>
    <dc:date>2018-05-31T10:29:51Z</dc:date>
    <item>
      <title>How handle JSON-Event with associative Array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-handle-JSON-Event-with-associative-Array/m-p/432708#M123645</link>
      <description>&lt;P&gt;Hi, &lt;BR /&gt;
i need a special result, but i dont know how to iterate over an associative array. &lt;/P&gt;

&lt;P&gt;Here is this JSON-Events: &lt;/P&gt;

&lt;P&gt;Event 1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
"created": "28\/May\/2018:06:24:00 +0200",
"response": {           
            "products": {
                "1": {
                    "id": 10,                       
                    "price": 120                        
                },
                "2": {
                    "id": 20,                       
                    "price": 65                     
                },
                "3": {
                    "id": 30,                       
                    "price": 80 
                }
            }
        }       
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Event 2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
"created": "30\/May\/2018:08:10:00 +0200",
"response": {           
            "products": {
                "1": {
                    "id": 40,                       
                    "price": 120                        
                },
                "2": {
                    "id": 50,                       
                    "price": 65                     
                }
            }
        }       
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And i need the folowing result: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ID      Price
-------------------
10      120
20      65
...      
50      65
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any idea? &lt;BR /&gt;
Many thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 10:29:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-handle-JSON-Event-with-associative-Array/m-p/432708#M123645</guid>
      <dc:creator>Roger_FB</dc:creator>
      <dc:date>2018-05-31T10:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: How handle JSON-Event with associative Array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-handle-JSON-Event-with-associative-Array/m-p/432709#M123646</link>
      <description>&lt;P&gt;The best approach would be to store arrays as arrays. Once you have that, you can use this to get to the individual array elements:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | spath response.products | mvexpand response.products | spath input=response.products
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The way your data is structured right now is that you have unknown/unbounded field/object names. Without known field/object names, how do you access fields/objects?&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 11:42:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-handle-JSON-Event-with-associative-Array/m-p/432709#M123646</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2018-05-31T11:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: How handle JSON-Event with associative Array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-handle-JSON-Event-with-associative-Array/m-p/432710#M123647</link>
      <description>&lt;P&gt;@Roger_FB &lt;/P&gt;

&lt;P&gt;Can you please try this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH 
| eval id="",price=""
| foreach response.products.*.id 
    [ eval id=id.if(id=="","",if(isnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),"",",")).if(isnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),"",'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')] 
| foreach response.products.*.price 
    [ eval price=price.if(price=="","",if(isnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),"",",")).if(isnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),"",'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')] 
| eval id=split(id,","),price=split(price,","),temp=mvzip(id,price) 
| mvexpand temp 
| table temp | eval id=mvindex(split(temp,","),0),price=mvindex(split(temp,","),1) | table id price
&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="{ \"created\": \"28\/May\/2018:06:24:00 +0200\", \"response\": {\"products\": { \"1\": { \"id\": 10,\"price\": 120}, \"2\": { \"id\": 20,\"price\": 65}, \"3\": { \"id\": 30,\"price\": 80 } } } }" 
| append 
    [| makeresults 
    | eval _raw="{\"created\": \"30\/May\/2018:08:10:00 +0200\",\"response\": {\"products\": {\"1\": {\"id\": 40,\"price\": 120},\"2\": {\"id\": 50,\"price\": 65}}}}"] 
| kv 
| eval id="",price="" 
| foreach response.products.*.id 
    [ eval id=id.if(id=="","",if(isnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),"",",")).if(isnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),"",'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;') ] 
| foreach response.products.*.price 
    [ eval price=price.if(price=="","",if(isnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),"",",")).if(isnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),"",'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;') ] 
| eval id=split(id,","),price=split(price,","),temp=mvzip(id,price) 
| mvexpand temp 
| table temp | eval id=mvindex(split(temp,","),0),price=mvindex(split(temp,","),1) | table id price
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jan 2019 11:34:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-handle-JSON-Event-with-associative-Array/m-p/432710#M123647</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-01-21T11:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: How handle JSON-Event with associative Array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-handle-JSON-Event-with-associative-Array/m-p/525668#M148365</link>
      <description>&lt;P&gt;Hey! Thanks so much for this!! The OP's problem was nearly identical to mine. I'm parsing thru Ansible's win_update JSon and they put in this stupid GUID thing for an object name...anyway...&lt;/P&gt;&lt;P&gt;I didn't know about having to pre populate my field for the foreach! I can't tell you how many hours and hours I spent wondering why, oh why, doesn't my foreach concatonation work???&lt;/P&gt;&lt;P&gt;I am totally stealing this from you.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval upd_kb=""
| foreach ansible_result.filtered_updates.*.kb{} [eval upd_kb=upd_kb.if(upd_kb=="","",if(isnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),"",",")).if(isnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),"",'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;') ] 
| table upd_kb&lt;/LI-CODE&gt;&lt;P&gt;I'm not sure if I'll need the isnull check, but it sure couldn't hurt to have!&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;&lt;P&gt;J&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 02:17:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-handle-JSON-Event-with-associative-Array/m-p/525668#M148365</guid>
      <dc:creator>indigo42</dc:creator>
      <dc:date>2020-10-21T02:17:41Z</dc:date>
    </item>
  </channel>
</rss>

