<?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: extract all the key-value pairs from the json data in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/extract-all-the-key-value-pairs-from-the-json-data/m-p/711319#M240144</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/170906"&gt;@livehybrid&lt;/a&gt;&lt;/P&gt;&lt;P&gt;this works like magic! thanks a lot for giving&amp;nbsp; me the insights!&lt;/P&gt;&lt;P&gt;Just wondering what's the reason at here that you did mvexpand twice&lt;/P&gt;&lt;P&gt;just did some test seems that&amp;nbsp; if I remove `| mvexpand data_value` I can still get the same results / format&lt;/P&gt;</description>
    <pubDate>Tue, 11 Feb 2025 22:44:51 GMT</pubDate>
    <dc:creator>darrfang</dc:creator>
    <dc:date>2025-02-11T22:44:51Z</dc:date>
    <item>
      <title>extract all the key-value pairs from the json data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-all-the-key-value-pairs-from-the-json-data/m-p/711307#M240140</link>
      <description>&lt;P&gt;Hi splunk team,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question about how to extract the key-value pair from json data. Let's say for example I have two raw data like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# raw data1:
{
  "key1": {
    "key2": {
      "key3": [
        {"data_value": {"aaa": "12345", "bbb": "23456"}}
      ]
    }
  }
}

# raw data 2:
{
  "key1": {
    "key2": {
      "key3": [
        {"data_value": {"ccc": "34567"}}
      ]
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how can I extract the key-value results in all the data_value, to be a table as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;node    value
aaa     12345
bbb     23456
ccc     34567&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;I current have a splunk query that could do part of it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;```some search...```
| spath output=pairs path=key1.key2.key3{}.data_value
| rex field=hwids "\"(?&amp;lt;node&amp;gt;[^\"]+)\":\"(?&amp;lt;value&amp;gt;[^\"]+)\""
| table node value pairs&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but this only gives me the result of all the first data, result would look like below, that ignore the data of&amp;nbsp;&amp;nbsp;"bbb":"23456". Please give me some advice on how to grab all the results, thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;node    value    pairs
aaa     12345    {"aaa": "12345", "bbb": "23456"}
ccc     34567    {"ccc": "34567"}&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;</description>
      <pubDate>Tue, 11 Feb 2025 19:41:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-all-the-key-value-pairs-from-the-json-data/m-p/711307#M240140</guid>
      <dc:creator>darrfang</dc:creator>
      <dc:date>2025-02-11T19:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: extract all the key-value pairs from the json data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-all-the-key-value-pairs-from-the-json-data/m-p/711310#M240142</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/269861"&gt;@darrfang&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How about this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
|  eval _raw="{
  \"key1\": {
    \"key2\": {
      \"key3\": [
        {\"data_value\": {\"aaa\": \"12345\", \"bbb\": \"23456\"}}
      ]
    }
  }
}"
| spath input=_raw output=data_value path=key1.key2.key3{}.data_value
| mvexpand data_value
| eval key_value=split(replace(data_value, "[\{\}\"]", ""), ",")
| mvexpand key_value
| rex field=key_value "\s?(?&amp;lt;node&amp;gt;[^:]+):(?&amp;lt;value&amp;gt;.*)"
| table node value&lt;/LI-CODE&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="livehybrid_0-1739305566560.png" style="width: 2158px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34460i60CAF2DEE4FA7E63/image-size/medium?v=v2&amp;amp;px=400" role="button" title="livehybrid_0-1739305566560.png" alt="livehybrid_0-1739305566560.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Please let me know how you get on and consider accepting this answer or adding karma this answer if it has helped.&lt;BR /&gt;Regards&lt;/P&gt;&lt;P&gt;Will&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2025 20:26:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-all-the-key-value-pairs-from-the-json-data/m-p/711310#M240142</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2025-02-11T20:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: extract all the key-value pairs from the json data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-all-the-key-value-pairs-from-the-json-data/m-p/711319#M240144</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/170906"&gt;@livehybrid&lt;/a&gt;&lt;/P&gt;&lt;P&gt;this works like magic! thanks a lot for giving&amp;nbsp; me the insights!&lt;/P&gt;&lt;P&gt;Just wondering what's the reason at here that you did mvexpand twice&lt;/P&gt;&lt;P&gt;just did some test seems that&amp;nbsp; if I remove `| mvexpand data_value` I can still get the same results / format&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2025 22:44:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-all-the-key-value-pairs-from-the-json-data/m-p/711319#M240144</guid>
      <dc:creator>darrfang</dc:creator>
      <dc:date>2025-02-11T22:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: extract all the key-value pairs from the json data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-all-the-key-value-pairs-from-the-json-data/m-p/711322#M240146</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/269861"&gt;@darrfang&lt;/a&gt;&amp;nbsp;When I tried I think it listed the two pairs within the same row in the table, whereas the second mvexpand broke them into their own rows.&lt;/P&gt;&lt;P&gt;I guess it depends what you're going to do with the data but if you wanted to sort or filter you might want them expanded further?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Either way, Im glad it worked out for you - Thanks for letting me know &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2025 23:04:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-all-the-key-value-pairs-from-the-json-data/m-p/711322#M240146</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2025-02-11T23:04:00Z</dc:date>
    </item>
  </channel>
</rss>

