<?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: parsing a JSON list in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/parsing-a-JSON-list/m-p/578325#M201551</link>
    <description>&lt;P&gt;Thank you so much!!! I really appreciate the help!&lt;/P&gt;</description>
    <pubDate>Tue, 14 Dec 2021 14:07:42 GMT</pubDate>
    <dc:creator>rberman</dc:creator>
    <dc:date>2021-12-14T14:07:42Z</dc:date>
    <item>
      <title>parsing a JSON list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/parsing-a-JSON-list/m-p/578273#M201521</link>
      <description>&lt;P&gt;Hi, I have a field called "catgories" whose&lt;SPAN&gt;&amp;nbsp;value is in the format of a JSON array. The array is a list of one or more category paths. The paths are in the form of a comma separated list of one or more (category_name:category_id) pairs.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Three example events have the following category data:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;"categories":"[{"categ_name_a":"categ_id_a","categ_name_b":"categ_id_b","categ_name_c":"categ_id_c"},{"categ_name_m":"categ_id_m","categ_name_n":"categ_id_n"},&lt;SPAN&gt;{"categ_name_z":"categ_id_z"}]"&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;"categories":"[{"categ_name_d":"categ_id_d","categ_name_e":"categ_id_e"}]"&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;"categories":"[{"categ_name_f":"categ_id_f"}]"&lt;/P&gt;&lt;P&gt;For each event, I am trying to extract the list of " &amp;gt;&amp;gt; " separated category_ids in each path into a multivalued field. So using the examples above I want to get a list of category paths:&lt;/P&gt;&lt;TABLE border="1" width="99.87096774193547%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="49.93548387096774%"&gt;event #&lt;/TD&gt;&lt;TD width="49.93548387096774%"&gt;&lt;U&gt;category_paths&lt;/U&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="49.93548387096774%"&gt;1&lt;/TD&gt;&lt;TD width="49.93548387096774%"&gt;&lt;P&gt;"categ_id_a &amp;gt;&amp;gt; categ_id_b &amp;gt;&amp;gt; categ_id_c"&lt;/P&gt;&lt;P&gt;"categ_id_m &amp;gt;&amp;gt; categ_id_n"&lt;/P&gt;&lt;P&gt;"categ_id_z"&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="49.93548387096774%"&gt;2&lt;/TD&gt;&lt;TD width="49.93548387096774%"&gt;"categ_id_d &amp;gt;&amp;gt; categ_id_e"&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="49.93548387096774%"&gt;3&lt;/TD&gt;&lt;TD width="49.93548387096774%"&gt;"categ_id_f"&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have no way of knowing what the category names or ids will be or how many (category_name:category_id) pairs there will be in each category path. I also won't know how many category paths are in the categories JSON array.&lt;/P&gt;&lt;P&gt;I have tried a bunch of ways to get at the data (spath, json_extract, regex) but I am new to this type of nested extraction.&lt;/P&gt;&lt;P&gt;| makeresults&lt;BR /&gt;| eval categories="[{\"categ_name_a\":\"categ_id_a\",\"categ_name_b\":\"categ_id_b\",\"categ_name_c\":\"categ_id_c\"},{\"categ_name_m\":\"categ_id_m\",\"categ_name_n\":\"categ_id_n\"},&lt;SPAN&gt;{\"categ_name_z\":\"categ_id_z\"}]&lt;/SPAN&gt;" | spath input=categories output=category_paths path={}&lt;/P&gt;&lt;P&gt;Can anyone help me?&lt;/P&gt;&lt;P&gt;Thanks!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 02:16:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/parsing-a-JSON-list/m-p/578273#M201521</guid>
      <dc:creator>rberman</dc:creator>
      <dc:date>2021-12-14T02:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a JSON list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/parsing-a-JSON-list/m-p/578293#M201533</link>
      <description>&lt;LI-CODE lang="markup"&gt;| makeresults
| eval categories="[{\"categ_name_a\":\"categ_id_a\",\"categ_name_b\":\"categ_id_b\",\"categ_name_c\":\"categ_id_c\"},{\"categ_name_m\":\"categ_id_m\",\"categ_name_n\":\"categ_id_n\"},{\"categ_name_z\":\"categ_id_z\"}]" | spath input=categories output=category_paths path={}


| streamstats count as event 
| mvexpand category_paths
| rex field=category_paths max_match=0 "\":\"(?&amp;lt;segment&amp;gt;[^\"]+)\""
| eval path=mvjoin(segment," &amp;gt;&amp;gt; ")
| fields - segment category_paths
| stats list(path) as category_paths by event&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 14 Dec 2021 09:49:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/parsing-a-JSON-list/m-p/578293#M201533</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-12-14T09:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a JSON list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/parsing-a-JSON-list/m-p/578325#M201551</link>
      <description>&lt;P&gt;Thank you so much!!! I really appreciate the help!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 14:07:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/parsing-a-JSON-list/m-p/578325#M201551</guid>
      <dc:creator>rberman</dc:creator>
      <dc:date>2021-12-14T14:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a JSON list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/parsing-a-JSON-list/m-p/578374#M201562</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;is there a way to use rex to get the multivalued path data straight out of the _raw string? I wanted to check if there were other approaches besides using spath and JSON extraction.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 20:13:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/parsing-a-JSON-list/m-p/578374#M201562</guid>
      <dc:creator>rberman</dc:creator>
      <dc:date>2021-12-14T20:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a JSON list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/parsing-a-JSON-list/m-p/578387#M201569</link>
      <description>&lt;P&gt;You could try this way without spath and mvexpand&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval categories="[{\"categ_name_a\":\"categ_id_a\",\"categ_name_b\":\"categ_id_b\",\"categ_name_c\":\"categ_id_c\"},{\"categ_name_m\":\"categ_id_m\",\"categ_name_n\":\"categ_id_n\"},{\"categ_name_z\":\"categ_id_z\"}]"

| rex field=categories max_match=0 "(?&amp;lt;category_paths&amp;gt;\{[^\}]+\})"
| rex field=category_paths mode=sed "s/}/,\"x\":\"|\"}/"
| rex field=category_paths max_match=0 "\":\"(?&amp;lt;segment&amp;gt;[^\"]+)\""
| eval category_paths=mvjoin(segment," &amp;gt;&amp;gt; ")
| fields - segment
| rex field=category_paths mode=sed "s/ &amp;gt;&amp;gt; \| &amp;gt;&amp;gt; /
/g"
| rex field=category_paths mode=sed "s/ &amp;gt;&amp;gt; \|//g"&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 14 Dec 2021 22:13:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/parsing-a-JSON-list/m-p/578387#M201569</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-12-14T22:13:46Z</dc:date>
    </item>
  </channel>
</rss>

