<?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 get only matching block values from nested json? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-only-matching-block-values-from-nested-json/m-p/625280#M217361</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;To give a problem background, I am trying to run a map command inside a search to get some values. THE JSON I am trying to access (sample below) has nested JSONs where I only need to read and derive value for the matched block. But as of now, my table command prints 3 rows instead of one (one row for each nested&amp;nbsp; JSON). I would like to print only the matching JSON block and ignore the other.&lt;BR /&gt;&lt;BR /&gt;I think rex and spath will be required here but it was still printing 3 rows as the final output but I need to print only 1 row. Not sure how to use them correctly to get the results. Please help.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;my sample search:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Index=Dummy X.id=AA11

| eval version=X.version
| eval connTrain=X.conTrainId----(value is TR2)

| map Index=ABC Y.TrainID=AA11 Y.version=$version$

Sample JSON is given below. In this case, I need to only access TR2 (second block)  and print its time and passenger value. In real-time, there can be only 1 JSON block or many and matching block can be at any location in case of multiple blocks.

{
          TrainID=AA11
            "TrainData": [
                    {

                        "ConnectingTrain": {
                                   "TR1": {
                                                  "connectionTime": "59",
                                                    "TotalPassengers": "44",
                                               },
                                 "TR2": {
                                                   "connectionTime": "33",
                                                    "TotalPassengers": "47",
                                              },
                               "TR3": {
                                                 "connectionTime": "51",
                                                 "TotalPassengers": "27",
                                             }
                                      }
                            }
                ]
}
&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 29 Dec 2022 04:08:52 GMT</pubDate>
    <dc:creator>chetanN</dc:creator>
    <dc:date>2022-12-29T04:08:52Z</dc:date>
    <item>
      <title>How to get only matching block values from nested json?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-only-matching-block-values-from-nested-json/m-p/625280#M217361</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;To give a problem background, I am trying to run a map command inside a search to get some values. THE JSON I am trying to access (sample below) has nested JSONs where I only need to read and derive value for the matched block. But as of now, my table command prints 3 rows instead of one (one row for each nested&amp;nbsp; JSON). I would like to print only the matching JSON block and ignore the other.&lt;BR /&gt;&lt;BR /&gt;I think rex and spath will be required here but it was still printing 3 rows as the final output but I need to print only 1 row. Not sure how to use them correctly to get the results. Please help.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;my sample search:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Index=Dummy X.id=AA11

| eval version=X.version
| eval connTrain=X.conTrainId----(value is TR2)

| map Index=ABC Y.TrainID=AA11 Y.version=$version$

Sample JSON is given below. In this case, I need to only access TR2 (second block)  and print its time and passenger value. In real-time, there can be only 1 JSON block or many and matching block can be at any location in case of multiple blocks.

{
          TrainID=AA11
            "TrainData": [
                    {

                        "ConnectingTrain": {
                                   "TR1": {
                                                  "connectionTime": "59",
                                                    "TotalPassengers": "44",
                                               },
                                 "TR2": {
                                                   "connectionTime": "33",
                                                    "TotalPassengers": "47",
                                              },
                               "TR3": {
                                                 "connectionTime": "51",
                                                 "TotalPassengers": "27",
                                             }
                                      }
                            }
                ]
}
&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 29 Dec 2022 04:08:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-only-matching-block-values-from-nested-json/m-p/625280#M217361</guid>
      <dc:creator>chetanN</dc:creator>
      <dc:date>2022-12-29T04:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to get only matching block values from nested json</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-only-matching-block-values-from-nested-json/m-p/625318#M217374</link>
      <description>&lt;P&gt;If you're posting a search, please include it in code block or a preformatted style - it helps reading and prevents the web service from mangling the indentations and so on. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Don't use map if you can avoid it! I know it's tempting, especially for someone new to Splunk (I've been there myself ;-)) but it's usually an attempt to do something in Splunk as you would normally do in other soultion (like SQL). It's most often not the way to go.&lt;/P&gt;&lt;P&gt;Try to describe what you want to achieve.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Dec 2022 10:24:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-only-matching-block-values-from-nested-json/m-p/625318#M217374</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-12-27T10:24:16Z</dc:date>
    </item>
  </channel>
</rss>

