<?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: List all unique keys present under certain json path in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649763#M224652</link>
    <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231013"&gt;@GaetanVP&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;I tried this same query using &lt;STRONG&gt;makeresult&lt;/STRONG&gt; as suggested by&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;, and it worked perfectly fine, I am not quite sure why it is not working with my production raw data.&lt;BR /&gt;due to some security reasons I may not be able to provide you raw data screenshot but it looks something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "severity": "INFO",
  "time": "2023-07-09 18:53:53.930",
  "Stats": {
    "discrepancy" : 10
  },
  "discrepancyDetails": {
    "record1/0": "#DEL",
    "record2/1": "#DEL",
    "record3": "expected =&amp;gt; actual",
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want all unique discrepancyDetails and its count,&lt;BR /&gt;anyway, I was able to get it through this query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="demo1" sourcetype="demo2" 
| search discrepancyDetails AND Stats 
| spath "Stats.discrepancy" 
| search "Stats.discrepancy" &amp;gt; 0 
| stats count(discrepancyDetails.*) as discrepancyDetails.*
| transpose&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I have some &lt;A href="https://community.splunk.com/t5/Splunk-Search/Fetching-statistics-Unique-discrepancy-details-removing/m-p/649764#M224653" target="_blank" rel="noopener"&gt;follow up queries&lt;/A&gt; on this. I may create a new thread for the same.&lt;BR /&gt;Thanks for your prompt response, really appreciated!&lt;/P&gt;</description>
    <pubDate>Mon, 10 Jul 2023 16:46:58 GMT</pubDate>
    <dc:creator>adikrhd</dc:creator>
    <dc:date>2023-07-10T16:46:58Z</dc:date>
    <item>
      <title>List all unique keys present under certain json path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649639#M224619</link>
      <description>&lt;P&gt;Hello Community,&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I stumbled across a scenario where I have events present in the JSON format as follows&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&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;
&lt;LI-CODE lang="javascript"&gt;Event 1: {
  "severity": "INFO",
  "message": "msg",
  "details": {
    "key1": "val1",
    "key2": "val2",
    "key3": "val3"
  }
}
.
.
.
Event n: {
  "severity": "INFOn",
  "message": "msgn",
  "details": {
    "key1n": "val1",
    "key2n": "val2",
    "key3n": "val3"
  }
}&lt;/LI-CODE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I want to list all the unique keys present under the path "details." I tried querying it using &lt;STRONG&gt;mvexpand&lt;/STRONG&gt; and &lt;STRONG&gt;json_keys&lt;/STRONG&gt;, but nothing seems to be working. I would greatly appreciate some assistance.&lt;BR /&gt;&lt;BR /&gt;The expected output should be as follows:&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;uniqueKeys:&lt;/STRONG&gt;&lt;BR /&gt;key1&lt;BR /&gt;key2&lt;BR /&gt;key3&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;key1n&lt;BR /&gt;key2n&lt;BR /&gt;key3n&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Basically, I want to list down all the unique keys present under the "details" JSON path across all the events..&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2023 18:38:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649639#M224619</guid>
      <dc:creator>adikrhd</dc:creator>
      <dc:date>2023-07-10T18:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: List all unique keys present under certain json path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649649#M224621</link>
      <description>&lt;P&gt;It would help to know what query you've tried so far.&amp;nbsp; Perhaps this is something different.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw="{
  \"severity\": \"INFO\",
  \"message\": \"msg\",
  \"details\": {
    \"key1\": \"val1\",
    \"key2\": \"val2\",
    \"key3\": \"val3\"
      }
}" 
``` Above just sets up demo data.  Delete IRL ```
| spath path=details 
| eval keys=json_keys(details)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 07 Jul 2023 15:35:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649649#M224621</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-07-07T15:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: List all unique keys present under certain json path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649650#M224622</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/258462"&gt;@adikrhd&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;You can try something like this&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;&amp;lt;your_search_that_give_the_big_json&amp;gt;&amp;gt;
| table details.*
| rename details.* AS "*" ```details.keysN will become keyN```
| untable _name, value ```reverse the table```
| dedup value
| sort value
| table _name, value&lt;/LI-CODE&gt;&lt;P&gt;Hope it helps !&lt;BR /&gt;GaetanVP&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 15:37:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649650#M224622</guid>
      <dc:creator>GaetanVP</dc:creator>
      <dc:date>2023-07-07T15:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: List all unique keys present under certain json path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649658#M224623</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Hope you are doing well.&lt;/P&gt;&lt;P&gt;I have already tried using the json_keys() approach, but the problem I encountered is that it returns a list of multivalue events in the result, something like this:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;keys&lt;BR /&gt;-----------&lt;BR /&gt;&lt;/STRONG&gt;["key1","key2","key3"]&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;["key1n","key2n","key3n"]&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But the ask here is that we want all unique keys in a single list. I am unable to figure out how to merge these two multivalues into a single unique list.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 16:37:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649658#M224623</guid>
      <dc:creator>adikrhd</dc:creator>
      <dc:date>2023-07-07T16:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: List all unique keys present under certain json path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649662#M224625</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231013"&gt;@GaetanVP&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;Appreciate your efforts here but it doesn't seem to be working,&amp;nbsp;&lt;BR /&gt;after &lt;STRONG&gt;untable _name value,&amp;nbsp;&lt;/STRONG&gt;it is not returning any visible stat results&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="adikrhd_0-1688748648984.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/26161i653850042E1991F0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="adikrhd_0-1688748648984.png" alt="adikrhd_0-1688748648984.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 16:52:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649662#M224625</guid>
      <dc:creator>adikrhd</dc:creator>
      <dc:date>2023-07-07T16:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: List all unique keys present under certain json path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649663#M224626</link>
      <description>&lt;P&gt;You can use json_array_to_mv to change keys to native array, then count array members.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path=details
| eval keys = json_array_to_mv(json_keys(details))
| stats values(keys) as unique_keys dc(keys) as unique_key_count&lt;/LI-CODE&gt;&lt;P&gt;This is a data emulation that you can play with and compare with real data&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval data = mvappend("{
  \"severity\": \"INFO\",
  \"message\": \"msg\",
  \"details\": {
    \"key1\": \"val1\",
    \"key2\": \"val2\",
    \"key3\": \"val3\"
  }
}",
"{
  \"severity\": \"INFOn\",
  \"message\": \"msgn\",
  \"details\": {
    \"key2\": \"val2a\",
    \"key1n\": \"val1\",
    \"key2n\": \"val2\",
    \"key3n\": \"val3\"
  }
}")
| mvexpand data
| rename data AS _raw
``` data emulation above ```&lt;/LI-CODE&gt;&lt;P&gt;Here, I added a duplicate key "key2" in the second event to test dedup.&lt;/P&gt;&lt;P&gt;You can also use untable as&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231013"&gt;@GaetanVP&lt;/a&gt;&amp;nbsp;suggested.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 16:58:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649663#M224626</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-07-07T16:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: List all unique keys present under certain json path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649664#M224627</link>
      <description>&lt;P&gt;Is the raw event in the same format as you illustrated? &amp;nbsp;untable should work just well if it is. &amp;nbsp;Here is an example with emulated data in the exact format as you illustrated:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval data = mvappend("{
  \"severity\": \"INFO\",
  \"message\": \"msg\",
  \"details\": {
    \"key1\": \"val1\",
    \"key2\": \"val2\",
    \"key3\": \"val3\"
  }
}",
"{
  \"severity\": \"INFOn\",
  \"message\": \"msgn\",
  \"details\": {
    \"key2\": \"val2a\",
    \"key1n\": \"val1\",
    \"key2n\": \"val2\",
    \"key3n\": \"val3\"
  }
}")
| mvexpand data
| rename data AS _raw
``` data emulation above ```
| spath
| table details.*
| rename details.* AS "*" ```details.keysN will become keyN```
| untable _name, value ```reverse the table```
| dedup value
``` I don't think you asked for sort ```
| table _name, value&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get this output:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;key1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;key2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;key3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;key1n&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;key2n&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;key3n&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 07 Jul 2023 17:07:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649664#M224627</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-07-07T17:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: List all unique keys present under certain json path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649665#M224628</link>
      <description>&lt;P&gt;Does this work any better?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval data="{
  \"severity\": \"INFO\",
  \"message\": \"msg\",
  \"details\": {
    \"key1\": \"val1\",
    \"key2\": \"val2\",
    \"key3\": \"val3\"
      }
}#{
  \"severity\": \"INFOn\",
  \"message\": \"msgn\",
  \"details\": {
    \"key1n\": \"val1\",
    \"key2n\": \"val2\",
    \"key3n\": \"val3\"
  }
}" 
| eval data=split(data,"#") | mvexpand data | eval _raw=data | fields - data
``` Above creates demo data.  Ignore IRL" ```
| spath path=details 
| eval keys=json_keys(details)
``` Strip out JSON array chars ```
| rex mode=sed field=keys "s/[\[\]\\\"]//g"
``` Separate each key into different events ```
| eval keys=split(keys,",")
| mvexpand keys
``` Get the unique key names ```
| stats values(keys) as keys&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 07 Jul 2023 17:10:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649665#M224628</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-07-07T17:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: List all unique keys present under certain json path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649670#M224630</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/258462"&gt;@adikrhd&lt;/a&gt;,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I suppose that we don't exactly have the same structure of data, could you give a screenshot of your data (basically when you just search your logs without any transformations) ?&lt;/P&gt;&lt;P&gt;Mine looks like this based on your first message&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GaetanVP_0-1688752435157.png" style="width: 610px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/26162i00A5058583F326EC/image-dimensions/610x567?v=v2" width="610" height="567" role="button" title="GaetanVP_0-1688752435157.png" alt="GaetanVP_0-1688752435157.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GaetanVP_1-1688752459007.png" style="width: 609px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/26163i4797C7407F48A9A5/image-dimensions/609x616?v=v2" width="609" height="616" role="button" title="GaetanVP_1-1688752459007.png" alt="GaetanVP_1-1688752459007.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I suspect that your data is not correclty ingested or maybe you have the "Event 1: " before each JSON, which we didn't take into account in all the answers on this topic I think...&lt;BR /&gt;&lt;BR /&gt;Keep us updated so we can find a fix!&lt;BR /&gt;GaetanVP&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 17:56:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649670#M224630</guid>
      <dc:creator>GaetanVP</dc:creator>
      <dc:date>2023-07-07T17:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: List all unique keys present under certain json path</title>
      <link>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649763#M224652</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231013"&gt;@GaetanVP&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;I tried this same query using &lt;STRONG&gt;makeresult&lt;/STRONG&gt; as suggested by&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;, and it worked perfectly fine, I am not quite sure why it is not working with my production raw data.&lt;BR /&gt;due to some security reasons I may not be able to provide you raw data screenshot but it looks something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "severity": "INFO",
  "time": "2023-07-09 18:53:53.930",
  "Stats": {
    "discrepancy" : 10
  },
  "discrepancyDetails": {
    "record1/0": "#DEL",
    "record2/1": "#DEL",
    "record3": "expected =&amp;gt; actual",
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want all unique discrepancyDetails and its count,&lt;BR /&gt;anyway, I was able to get it through this query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="demo1" sourcetype="demo2" 
| search discrepancyDetails AND Stats 
| spath "Stats.discrepancy" 
| search "Stats.discrepancy" &amp;gt; 0 
| stats count(discrepancyDetails.*) as discrepancyDetails.*
| transpose&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I have some &lt;A href="https://community.splunk.com/t5/Splunk-Search/Fetching-statistics-Unique-discrepancy-details-removing/m-p/649764#M224653" target="_blank" rel="noopener"&gt;follow up queries&lt;/A&gt; on this. I may create a new thread for the same.&lt;BR /&gt;Thanks for your prompt response, really appreciated!&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2023 16:46:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/List-all-unique-keys-present-under-certain-json-path/m-p/649763#M224652</guid>
      <dc:creator>adikrhd</dc:creator>
      <dc:date>2023-07-10T16:46:58Z</dc:date>
    </item>
  </channel>
</rss>

