<?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: find and extract a json object from a json array based on other json field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614441#M213548</link>
    <description>&lt;P&gt;Thanks &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt; . But I want to get a line that looks like this:&lt;/P&gt;&lt;TABLE border="1" width="24.298748402440722%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="14.122137404580151%"&gt;student_id&lt;/TD&gt;&lt;TD width="10.178117048346067%"&gt;name&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="14.122137404580151%"&gt;456&lt;/TD&gt;&lt;TD width="10.178117048346067%"&gt;def&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;(because the id of "def" is the student_id "456")&lt;/P&gt;</description>
    <pubDate>Sun, 25 Sep 2022 07:39:50 GMT</pubDate>
    <dc:creator>asafd</dc:creator>
    <dc:date>2022-09-25T07:39:50Z</dc:date>
    <item>
      <title>How to find and extract a json object from a json array based on other json field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614433#M213542</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have rows that are json based. each row has a field that looks like this:&lt;/P&gt;
&lt;PRE&gt;{ &lt;BR /&gt;  "students" : [ &lt;BR /&gt;    {"id":"123", "name":"abc"},&lt;BR /&gt;    {"id":"456", "name":"def"},&lt;BR /&gt;    {"id":"789", "name":"hij"}&lt;BR /&gt;  ],&lt;BR /&gt;  "student_id" : "456"&lt;BR /&gt;}&lt;/PRE&gt;
&lt;P&gt;each row can have multiple &lt;EM&gt;students&lt;/EM&gt; and always just one &lt;EM&gt;student_id&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;for each row I want to extract the name of the student who's &lt;EM&gt;id&lt;/EM&gt; is equal to the &lt;EM&gt;student_id&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;how can I do that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried this,:&lt;/P&gt;
&lt;PRE&gt; |spath path=students{} output=students|mvexpand students | spath input=students|multikv| table id, name, student_id&lt;/PRE&gt;
&lt;P&gt;I do get 3 rows like this in the result:&lt;/P&gt;
&lt;TABLE border="1" width="35.6053885521952%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="6.18686868686869%"&gt;&lt;FONT face="courier new,courier"&gt;id&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="12.5%"&gt;&lt;FONT face="courier new,courier"&gt;name&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="16.91919191919193%"&gt;&lt;FONT face="courier new,courier"&gt;student_id&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="6.18686868686869%"&gt;&lt;FONT face="courier new,courier"&gt;123&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="12.5%"&gt;&lt;FONT face="courier new,courier"&gt;abc&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="16.91919191919193%"&gt;&lt;FONT face="courier new,courier"&gt;456&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="6.18686868686869%"&gt;&lt;FONT face="courier new,courier"&gt;456&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="12.5%"&gt;&lt;FONT face="courier new,courier"&gt;def&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="16.91919191919193%"&gt;&lt;FONT face="courier new,courier"&gt;456&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="6.18686868686869%"&gt;&lt;FONT face="courier new,courier"&gt;789&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="12.5%"&gt;&lt;FONT face="courier new,courier"&gt;hij&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="16.91919191919193%"&gt;&lt;FONT face="courier new,courier"&gt;456&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but when I try to filter the matching row with:&lt;/P&gt;
&lt;PRE&gt;| where id = student_id&lt;/PRE&gt;
&lt;P&gt;I get 0 rows coming back.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TIA&lt;/P&gt;
&lt;P&gt;Asaf&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 15:23:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614433#M213542</guid>
      <dc:creator>asafd</dc:creator>
      <dc:date>2022-09-26T15:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: find and extract a json object from a json array based on other json field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614434#M213543</link>
      <description>&lt;P&gt;Depends on how you want the names displayed or used subsequently. &amp;nbsp;Here's a simple example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath input=row
| stats values(students{}.name) by student_id&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="andale mono,times"&gt;row&lt;/FONT&gt;, of source, means the data field that holds this JSON object. &amp;nbsp;The output will look like&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;student_id&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;values(students{}.name)&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;456&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;abc&lt;/DIV&gt;&lt;DIV class=""&gt;def&lt;/DIV&gt;&lt;DIV class=""&gt;hij&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sat, 24 Sep 2022 20:32:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614434#M213543</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-09-24T20:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: find and extract a json object from a json array based on other json field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614441#M213548</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt; . But I want to get a line that looks like this:&lt;/P&gt;&lt;TABLE border="1" width="24.298748402440722%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="14.122137404580151%"&gt;student_id&lt;/TD&gt;&lt;TD width="10.178117048346067%"&gt;name&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="14.122137404580151%"&gt;456&lt;/TD&gt;&lt;TD width="10.178117048346067%"&gt;def&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;(because the id of "def" is the student_id "456")&lt;/P&gt;</description>
      <pubDate>Sun, 25 Sep 2022 07:39:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614441#M213548</guid>
      <dc:creator>asafd</dc:creator>
      <dc:date>2022-09-25T07:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: find and extract a json object from a json array based on other json field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614446#M213549</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/249770"&gt;@asafd&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think your search should work.&lt;/P&gt;&lt;P&gt;Can you please try this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw="{ \"students\" : [ {\"id\":\"123\", \"name\":\"abc\"},{\"id\":\"456\", \"name\":\"def\"},{\"id\":\"789\", \"name\":\"hij\"}],\"student_id\" : \"456\"}" 
| kv
|rename comment as "upto this is sample data" 
| spath path=students{} output=students 
| mvexpand students 
| spath input=students 
| multikv 
| table id, name, student_id
| where id = student_id&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-09-25 at 1.31.13 PM.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/21651i027E7A42FBAB3714/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2022-09-25 at 1.31.13 PM.png" alt="Screenshot 2022-09-25 at 1.31.13 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You can try this also.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw="{ \"students\" : [ {\"id\":\"123\", \"name\":\"abc\"},{\"id\":\"456\", \"name\":\"def\"},{\"id\":\"789\", \"name\":\"hij\"}],\"student_id\" : \"456\"}" 
| spath 
|rename comment as "upto this is sample data" 
| eval t = mvzip('students{}.id','students{}.name') 
| mvexpand t 
| eval id=mvindex(split(t,","),0), name=mvindex(split(t,","),1) 
| table id name student_id
| where id = student_id&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-09-25 at 1.33.41 PM.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/21652i852E42F04098077C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2022-09-25 at 1.33.41 PM.png" alt="Screenshot 2022-09-25 at 1.33.41 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this will help you.&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Sep 2022 08:04:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614446#M213549</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2022-09-25T08:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: find and extract a json object from a json array based on other json field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614448#M213550</link>
      <description>&lt;LI-CODE lang="markup"&gt;| spath path=students{} output=students 
| mvexpand students 
| spath input=students 
| where id = student_id
| table student_id, name&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 25 Sep 2022 08:55:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614448#M213550</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-09-25T08:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: find and extract a json object from a json array based on other json field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614451#M213551</link>
      <description>&lt;P&gt;Thank you very much. This also worked for me eventually, but you solutions are nicer (I hate regex :-)).&lt;/P&gt;&lt;PRE&gt;| makeresults &lt;BR /&gt;| eval _raw="{\"message\":{\"res\":{\"body\":{\"embeddedObj\":{\"students\":[{\"id\":\"123\",\"name\":\"abc\"},{\"id\":\"456\",\"name\":\"def\"},{\"id\":\"789\",\"name\":\"hij\"}],\"student_id\":\"456\"}}}}}" &lt;BR /&gt;| spath&lt;BR /&gt;|rename message.res.body.embeddedObj.students{}.id as ids message.res.body.embeddedObj.students{}.name as names message.res.body.embeddedObj.student_id as student_id&lt;BR /&gt;| eval student_zip = mvzip(ids, names)|mvexpand student_zip&lt;BR /&gt;| rex field=student_zip "^(?&amp;lt;id&amp;gt;.*),(?&amp;lt;name&amp;gt;.*)"&lt;BR /&gt;| where id = student_id| table id, name&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Sep 2022 10:03:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614451#M213551</guid>
      <dc:creator>asafd</dc:creator>
      <dc:date>2022-09-25T10:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: find and extract a json object from a json array based on other json field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614466#M213552</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/249770"&gt;@asafd&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Thanks &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt; . But I want to get a line that looks like this:&lt;/P&gt;&lt;TABLE border="1" width="24.298748402440722%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="14.122137404580151%"&gt;student_id&lt;/TD&gt;&lt;TD width="10.178117048346067%"&gt;name&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="14.122137404580151%"&gt;456&lt;/TD&gt;&lt;TD width="10.178117048346067%"&gt;def&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;(because the id of "def" is the student_id "456")&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That's exactly why I prefaced my answer with "depends on how you want it." &amp;nbsp;For this effect, you go&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath input=row
| stats values(students{}.name) by student_id
| mvexpand values(students{}.name)
| rename values(students{}.name) AS name&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;student_id&lt;/TD&gt;&lt;TD&gt;name&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;456&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;456&lt;/TD&gt;&lt;TD&gt;def&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;456&lt;/TD&gt;&lt;TD&gt;hij&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sun, 25 Sep 2022 23:50:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-and-extract-a-json-object-from-a-json-array-based-on/m-p/614466#M213552</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-09-25T23:50:22Z</dc:date>
    </item>
  </channel>
</rss>

