<?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 to properly extract into individual fields with a complicated nested json array in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-properly-extract-into-individual-fields-with-a/m-p/584382#M203496</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Warning:&amp;nbsp;&lt;/STRONG&gt; Long, detailed explanation ahead. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; &amp;nbsp;Summary version is that&amp;nbsp;I have a nested json arrays and fields that I am having an issue with extracting properly into individual fields.&amp;nbsp;&amp;nbsp;The chosen fields will change over time, based on external factors so I need to be able to extract and report on all of them, with the ability to identify the array index (i.e. {0}, or {1}, etc).&amp;nbsp; &amp;nbsp;No solution that I have looked at or come up with is working for me, so I am turning to you smarter folks to help.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Detail:&lt;/STRONG&gt;&lt;BR /&gt;I have a nested json arrays and fields that I am having an issue with extracting properly into individual fields.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;The end result is that I want to be able to place alerts or report on various fields that are deemed interesting.&lt;BR /&gt;&lt;BR /&gt;These are "request" and "response" arrays in each transaction (think checking items in a shopping cart for various flag and indicators).&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The chosen fields will change over time, based on external factors so I need to be able to extract them from the array&amp;nbsp; and report on all of them at some point.&lt;BR /&gt;&lt;BR /&gt;Here is a sample request and response&lt;/P&gt;&lt;DIV class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="market basket json.jpg" style="width: 929px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/17903i158CBB41A4166BD2/image-size/large?v=v2&amp;amp;px=999" role="button" title="market basket json.jpg" alt="market basket json.jpg" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;As you can see the the request array is market_basket.request{} and the response is market_basket.response{}. Focusing on the response portion, the first response has an "02" field and a "dataset". The next response{1} has fields 02,03,04,05,08,etc etc., same with response{2} and response{3}&lt;/P&gt;&lt;P&gt;if I do a simple rename&lt;BR /&gt;&lt;EM&gt;| rename market_basket.response.* to Resp_* &lt;/EM&gt;&lt;BR /&gt;the fields don't line up. The contents of "Resp_19" should be down 1 line as there was no field 19 in market_basket.response{0}.&amp;nbsp; See here:&amp;nbsp;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="market basket rename.jpg" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/17904i9FEB7F49C0B39E05/image-size/large?v=v2&amp;amp;px=999" role="button" title="market basket rename.jpg" alt="market basket rename.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If I change the query to this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path=market_basket.response{} output=Response
| spath input=Response
| table tran_id 0* 1* 2*  dataset&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I only get the first row, the other 3 rows don't show up.&lt;BR /&gt;&lt;BR /&gt;The only way that I have been able to get it to work is to address each indices and&amp;nbsp; field individually&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path=market_basket.response{0} output=Resp_0 
| spath path=market_basket.response{0}.dataset output=Resp_0_dataset 
| spath path=market_basket.response{0}.02 output=Resp_0_02 
| spath path=market_basket.response{1} output=Resp_1 
| spath path=market_basket.response{1}.dataset output=Resp_1_dataset 
| spath path=market_basket.response{1}.01 output=Resp_1_01 
| spath path=market_basket.response{1}.02 output=Resp_1_02 
| spath path=market_basket.response{1}.03 output=Resp_1_03 
| spath path=market_basket.response{1}.04 output=Resp_1_04 
| spath path=market_basket.response{1}.05 output=Resp_1_05 
| spath path=market_basket.response{1}.06 output=Resp_1_06 
| spath path=market_basket.response{1}.07 output=Resp_1_07 
| spath path=market_basket.response{1}.08 output=Resp_1_08 
| spath path=market_basket.response{1}.09 output=Resp_1_09 
| spath path=market_basket.response{1}.10 output=Resp_1_10 
| spath path=market_basket.response{1}.11 output=Resp_1_11 
| spath path=market_basket.response{1}.12 output=Resp_1_12 
| spath path=market_basket.response{1}.13 output=Resp_1_13 
| spath path=market_basket.response{1}.14 output=Resp_1_14 
| spath path=market_basket.response{1}.15 output=Resp_1_15 
| spath path=market_basket.response{1}.16 output=Resp_1_16 
| spath path=market_basket.response{1}.17 output=Resp_1_17 
| spath path=market_basket.response{1}.18 output=Resp_1_18 
| spath path=market_basket.response{1}.19 output=Resp_1_19 
| spath path=market_basket.response{1}.20 output=Resp_1_20 
| spath path=market_basket.response{1}.21 output=Resp_1_21 
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But with up to 60 responses with 20 fields per transaction, that many spaths would be a non-starter. Especially considering that I need to factor in the request portions too at some point.&lt;BR /&gt;&lt;BR /&gt;Finally, to give an example use case, I want to be able to check field 19 on the response&amp;nbsp; and if the flag starts with "NN" or "NY", then put out an alert: "Item".&lt;EM&gt;market_basket{whatever #}.02.&lt;/EM&gt;" has been not been cleared for sale". Flags are:".&lt;EM&gt;market_basket{whatever #].19&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;I know that was a lot of detail, but I wanted to make sure that I put down the different ways that I tried.&lt;BR /&gt;Any help would be much appreciated!&lt;/P&gt;</description>
    <pubDate>Wed, 09 Feb 2022 20:43:38 GMT</pubDate>
    <dc:creator>randy_moore</dc:creator>
    <dc:date>2022-02-09T20:43:38Z</dc:date>
    <item>
      <title>How to properly extract into individual fields with a complicated nested json array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-properly-extract-into-individual-fields-with-a/m-p/584382#M203496</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Warning:&amp;nbsp;&lt;/STRONG&gt; Long, detailed explanation ahead. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; &amp;nbsp;Summary version is that&amp;nbsp;I have a nested json arrays and fields that I am having an issue with extracting properly into individual fields.&amp;nbsp;&amp;nbsp;The chosen fields will change over time, based on external factors so I need to be able to extract and report on all of them, with the ability to identify the array index (i.e. {0}, or {1}, etc).&amp;nbsp; &amp;nbsp;No solution that I have looked at or come up with is working for me, so I am turning to you smarter folks to help.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Detail:&lt;/STRONG&gt;&lt;BR /&gt;I have a nested json arrays and fields that I am having an issue with extracting properly into individual fields.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;The end result is that I want to be able to place alerts or report on various fields that are deemed interesting.&lt;BR /&gt;&lt;BR /&gt;These are "request" and "response" arrays in each transaction (think checking items in a shopping cart for various flag and indicators).&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The chosen fields will change over time, based on external factors so I need to be able to extract them from the array&amp;nbsp; and report on all of them at some point.&lt;BR /&gt;&lt;BR /&gt;Here is a sample request and response&lt;/P&gt;&lt;DIV class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="market basket json.jpg" style="width: 929px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/17903i158CBB41A4166BD2/image-size/large?v=v2&amp;amp;px=999" role="button" title="market basket json.jpg" alt="market basket json.jpg" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;As you can see the the request array is market_basket.request{} and the response is market_basket.response{}. Focusing on the response portion, the first response has an "02" field and a "dataset". The next response{1} has fields 02,03,04,05,08,etc etc., same with response{2} and response{3}&lt;/P&gt;&lt;P&gt;if I do a simple rename&lt;BR /&gt;&lt;EM&gt;| rename market_basket.response.* to Resp_* &lt;/EM&gt;&lt;BR /&gt;the fields don't line up. The contents of "Resp_19" should be down 1 line as there was no field 19 in market_basket.response{0}.&amp;nbsp; See here:&amp;nbsp;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="market basket rename.jpg" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/17904i9FEB7F49C0B39E05/image-size/large?v=v2&amp;amp;px=999" role="button" title="market basket rename.jpg" alt="market basket rename.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If I change the query to this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path=market_basket.response{} output=Response
| spath input=Response
| table tran_id 0* 1* 2*  dataset&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I only get the first row, the other 3 rows don't show up.&lt;BR /&gt;&lt;BR /&gt;The only way that I have been able to get it to work is to address each indices and&amp;nbsp; field individually&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path=market_basket.response{0} output=Resp_0 
| spath path=market_basket.response{0}.dataset output=Resp_0_dataset 
| spath path=market_basket.response{0}.02 output=Resp_0_02 
| spath path=market_basket.response{1} output=Resp_1 
| spath path=market_basket.response{1}.dataset output=Resp_1_dataset 
| spath path=market_basket.response{1}.01 output=Resp_1_01 
| spath path=market_basket.response{1}.02 output=Resp_1_02 
| spath path=market_basket.response{1}.03 output=Resp_1_03 
| spath path=market_basket.response{1}.04 output=Resp_1_04 
| spath path=market_basket.response{1}.05 output=Resp_1_05 
| spath path=market_basket.response{1}.06 output=Resp_1_06 
| spath path=market_basket.response{1}.07 output=Resp_1_07 
| spath path=market_basket.response{1}.08 output=Resp_1_08 
| spath path=market_basket.response{1}.09 output=Resp_1_09 
| spath path=market_basket.response{1}.10 output=Resp_1_10 
| spath path=market_basket.response{1}.11 output=Resp_1_11 
| spath path=market_basket.response{1}.12 output=Resp_1_12 
| spath path=market_basket.response{1}.13 output=Resp_1_13 
| spath path=market_basket.response{1}.14 output=Resp_1_14 
| spath path=market_basket.response{1}.15 output=Resp_1_15 
| spath path=market_basket.response{1}.16 output=Resp_1_16 
| spath path=market_basket.response{1}.17 output=Resp_1_17 
| spath path=market_basket.response{1}.18 output=Resp_1_18 
| spath path=market_basket.response{1}.19 output=Resp_1_19 
| spath path=market_basket.response{1}.20 output=Resp_1_20 
| spath path=market_basket.response{1}.21 output=Resp_1_21 
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But with up to 60 responses with 20 fields per transaction, that many spaths would be a non-starter. Especially considering that I need to factor in the request portions too at some point.&lt;BR /&gt;&lt;BR /&gt;Finally, to give an example use case, I want to be able to check field 19 on the response&amp;nbsp; and if the flag starts with "NN" or "NY", then put out an alert: "Item".&lt;EM&gt;market_basket{whatever #}.02.&lt;/EM&gt;" has been not been cleared for sale". Flags are:".&lt;EM&gt;market_basket{whatever #].19&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;I know that was a lot of detail, but I wanted to make sure that I put down the different ways that I tried.&lt;BR /&gt;Any help would be much appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 20:43:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-properly-extract-into-individual-fields-with-a/m-p/584382#M203496</guid>
      <dc:creator>randy_moore</dc:creator>
      <dc:date>2022-02-09T20:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly extract into individual fields with a complicated nested json array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-properly-extract-into-individual-fields-with-a/m-p/584386#M203497</link>
      <description>&lt;P&gt;Well, splunk is not keeping track of fancy json structure and doesn't really care about indexes in arrays in json structures and addressing them in simple evals.&lt;/P&gt;&lt;P&gt;True, with spath it's possible to addres individually addressed subelements but that's how spath (which is a much "heavier" machinery than a simple eval) works. Furthermore, splunk itself isn't very much into complicated data structures. You can't do a two-dimensional array. Multivalued fiels is the most you can count on.&lt;/P&gt;&lt;P&gt;You could try to split the response into a multivalued field consisting of the "subjsons", do mvexpand to divide it into separate events and then do spath on that field.&lt;/P&gt;&lt;P&gt;Something like that:&lt;/P&gt;&lt;PRE&gt;| spath "market_basket.response{}" output=my_responses&lt;BR /&gt;| mvexpand my_responses&lt;BR /&gt;| spath input=my_responses&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Feb 2022 21:03:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-properly-extract-into-individual-fields-with-a/m-p/584386#M203497</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-02-09T21:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly extract into individual fields with a complicated nested json array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-properly-extract-into-individual-fields-with-a/m-p/584387#M203498</link>
      <description>&lt;P&gt;If it's true that the first response array element is always just 02 and dataset, then this would do the trick after your rename&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval Resp_02=mvindex(Resp_02,1,99), Resp_dataset=mvindex(Resp_dataset,1,99)&lt;/LI-CODE&gt;&lt;P&gt;i.e. just remove the first element from those two multivalue fields.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 21:27:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-properly-extract-into-individual-fields-with-a/m-p/584387#M203498</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-02-09T21:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly extract into individual fields with a complicated nested json array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-properly-extract-into-individual-fields-with-a/m-p/584691#M203682</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/182456"&gt;@randy_moore&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;If I change the query to this&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100%"&gt;&lt;FONT face="courier new,courier"&gt;| spath path=market_basket.response{} output=Response&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| spath input=Response&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| table tran_id 0* 1* 2* dataset&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Then I only get the first row, the other 3 rows don't show up.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;What&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;&amp;nbsp; meant was&lt;/P&gt;&lt;PRE&gt;| spath path=market_basket.response{} output=Responses&lt;BR /&gt;| mvexpand Responses&lt;BR /&gt;| spath input=Responses&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;In other words, just add&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Mvexpand#mvexpand" target="_blank" rel="noopener"&gt;mvexpand&lt;/A&gt;&amp;nbsp;&lt;SPAN&gt;to your quoted query. &amp;nbsp;Every element in the response array will be in its own row.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Consider these points:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;It is really unclear what the end goal is. &amp;nbsp;If you want to tabulate all key-value combinations including non-existence (null), PickleRick's&amp;nbsp;method suffices. &amp;nbsp;You can then flatten field names with "&lt;EM&gt;| rename response.* to Resp_*&lt;/EM&gt;" Such tabulation also allows you to &amp;nbsp;do many other things.&lt;/LI&gt;&lt;LI&gt;It is best to illustrate input data with text, not screenshot. &amp;nbsp;It is a lot easier for people to generate ideas with data that can be passed into Splunk.&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Fri, 11 Feb 2022 10:32:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-properly-extract-into-individual-fields-with-a/m-p/584691#M203682</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-02-11T10:32:34Z</dc:date>
    </item>
  </channel>
</rss>

