<?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 extract the first element from the JSON element based on a field match? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-first-element-from-the-JSON-element-based-on/m-p/649677#M224634</link>
    <description>&lt;P&gt;Note your JSON illustration is invalid. &amp;nbsp;I assume you meant&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100%"&gt;&lt;SPAN&gt;{"payload":[{"name":"suman", "age":"22"},{"name":"raman", "age":"32"}]}&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;(This means that you have fields like payload{}.name and payload{}.age.) &amp;nbsp;You can use mvexpand then search, like&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path=payload{}
| mvexpand payload{}
| spath input=payload{}
| where age == "22"&lt;/LI-CODE&gt;&lt;P&gt;Or, you can use mvfind with mvindex, like&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval match_name = mvindex('payload{}.name', mvfind('payload{}.age', "22"))
| eval match = json_object("age", "22", "name", match_name)&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 07 Jul 2023 19:10:26 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2023-07-07T19:10:26Z</dc:date>
    <item>
      <title>How to extract the first element from the JSON element based on a field match?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-first-element-from-the-JSON-element-based-on/m-p/649674#M224632</link>
      <description>&lt;P&gt;I want to extract the json object based on a single field match from below string message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;payload ::[{"name","suman", "age":"22"},{"name","raman", "age":"32"}]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;If the age is 22 then print {"name","suman", "age":"22"}&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 18:39:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-first-element-from-the-JSON-element-based-on/m-p/649674#M224632</guid>
      <dc:creator>Chandra</dc:creator>
      <dc:date>2023-07-07T18:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the first element from the JSON element based on a field match?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-first-element-from-the-JSON-element-based-on/m-p/649677#M224634</link>
      <description>&lt;P&gt;Note your JSON illustration is invalid. &amp;nbsp;I assume you meant&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100%"&gt;&lt;SPAN&gt;{"payload":[{"name":"suman", "age":"22"},{"name":"raman", "age":"32"}]}&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;(This means that you have fields like payload{}.name and payload{}.age.) &amp;nbsp;You can use mvexpand then search, like&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path=payload{}
| mvexpand payload{}
| spath input=payload{}
| where age == "22"&lt;/LI-CODE&gt;&lt;P&gt;Or, you can use mvfind with mvindex, like&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval match_name = mvindex('payload{}.name', mvfind('payload{}.age', "22"))
| eval match = json_object("age", "22", "name", match_name)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 07 Jul 2023 19:10:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-first-element-from-the-JSON-element-based-on/m-p/649677#M224634</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-07-07T19:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the first element from the JSON element based on a field match?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-first-element-from-the-JSON-element-based-on/m-p/649678#M224635</link>
      <description>&lt;LI-CODE lang="markup"&gt;| rex "(?&amp;lt;nameage&amp;gt;\{\"name\",\"[^\"]+\", \"age\":\"22\"\})"&lt;/LI-CODE&gt;&lt;P&gt;However, given that this is not valid JSON, you might want to change the first comma (,) to a colon (:) to match JSON format. You also might need to include some white spaces (\s) in the match strings. (Since you have obviously provided a dummy example, there may be other tweaks you need to make!)&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 19:12:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-first-element-from-the-JSON-element-based-on/m-p/649678#M224635</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-07-07T19:12:53Z</dc:date>
    </item>
  </channel>
</rss>

