<?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: SPATH usage on simple JSON in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-table-using-SPATH-usage-on-simple-JSON/m-p/588863#M205080</link>
    <description>&lt;P&gt;In my test, whether the field name is ip_addresses or _ip_addresses, "foreach ip_addresses.*.value" matches just as well. &amp;nbsp;So, you shouldn't have to make any change. &amp;nbsp;How does it work in your case?&lt;/P&gt;&lt;P&gt;Below, one simulated event uses ip_addresses, the other _ip_addresses.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval data=mvappend("{
        \"ip_addresses\": {
                \"10.0.0.1\": {
                        \"value\": \"some v4 ip\",
                        \"expire\": 1749267900
                },
                \"2001:53f1:3:2ee:2252:12e3:228a:112a\": {
                        \"value\": \"some v6 ip\"
                }
        }
}","{
        \"_ip_addresses\": {
                \"10.0.0.2\": {
                        \"value\": \"some v4 ip\",
                        \"expire\": 1749267900
                },
                \"2001:53f1:3:2ee:2252:12e3:228a:112b\": {
                        \"value\": \"some v6 ip\"
                }
        }
}")
| mvexpand data
| rename data as _raw
| spath
``` simulate data ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The search works in both&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;key&lt;/TD&gt;&lt;TD&gt;value&lt;/TD&gt;&lt;TD&gt;expire&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="294.078125px" height="25px"&gt;10.0.0.1&lt;/TD&gt;&lt;TD width="88.59375px" height="25px"&gt;some v4 ip&lt;/TD&gt;&lt;TD width="107.015625px" height="25px"&gt;1749267900&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="294.078125px" height="25px"&gt;2001:53f1:3:2ee:2252:12e3:228a:112a&lt;/TD&gt;&lt;TD width="88.59375px" height="25px"&gt;some v6 ip&lt;/TD&gt;&lt;TD width="107.015625px" height="25px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="294.078125px" height="25px"&gt;10.0.0.2&lt;/TD&gt;&lt;TD width="88.59375px" height="25px"&gt;some v4 ip&lt;/TD&gt;&lt;TD width="107.015625px" height="25px"&gt;1749267900&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="294.078125px" height="25px"&gt;2001:53f1:3:2ee:2252:12e3:228a:112b&lt;/TD&gt;&lt;TD width="88.59375px" height="25px"&gt;some v6 ip&lt;/TD&gt;&lt;TD width="107.015625px" height="25px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(If there is neither ip_address nor _ip_address in raw data, yes, mvexpand will not have data to work with. The warning is therefore expected.)&lt;/P&gt;</description>
    <pubDate>Mon, 14 Mar 2022 02:50:37 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2022-03-14T02:50:37Z</dc:date>
    <item>
      <title>How to create a table using SPATH usage on simple JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-table-using-SPATH-usage-on-simple-JSON/m-p/588837#M205069</link>
      <description>&lt;P&gt;Hi All -&lt;/P&gt;
&lt;P&gt;I am working with a very simple database that stores lists of key=value pairs with a potential expiration date and provides a REST API that outputs this data in JSON.&lt;/P&gt;
&lt;P&gt;I've played with spath for a few hours now and am completely stumped.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Note: The JSON retrieved is not from a search or from another data input. It's from a custom curl command that creates its own results and displays them. I do not believe modifying the kv_mode on this app I'm working on would have any effect.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Here is an example of the data I'm working with. Each entry in the object is an IP address, with a value and an optional expiration along with it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{
	"ip_addresses": {
		"10.0.0.1": {
			"value": "some v4 ip",
			"expire": 1749267900
		},
		"2001:53f1:3:2ee:2252:12e3:228a:112a": {
			"value": "some v6 ip"
		}
	}
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I need to be able to display this information in a table like:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;Key&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;Value&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;Expiration&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;10.0.0.1&lt;/TD&gt;
&lt;TD&gt;some v4 ip&lt;/TD&gt;
&lt;TD&gt;1749267900&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;2001:53f1:3:2ee:2252:12e3:228a:112a&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;some v6 ip&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help on this would be greatly appreciated. Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 13:42:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-table-using-SPATH-usage-on-simple-JSON/m-p/588837#M205069</guid>
      <dc:creator>rps462</dc:creator>
      <dc:date>2022-03-14T13:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: SPATH usage on simple JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-table-using-SPATH-usage-on-simple-JSON/m-p/588838#M205070</link>
      <description>&lt;P&gt;This is very similar to&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/How-to-Extract-JSON-format-as-fields/m-p/586925" target="_blank" rel="noopener"&gt;https://community.splunk.com/t5/Splunk-Search/How-to-Extract-JSON-format-as-fields/m-p/586925&lt;/A&gt;. &amp;nbsp;What makes this one different is that the missing portion is in field name, not array value. But it can be handled. &amp;nbsp;Here is a test with the sample data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;``` after spath ```
| foreach ip_addresses.*.value
    [eval keyvalue=mvappend(keyvalue, "&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;" . "|" . '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')]
| mvexpand keyvalue
| eval key=mvindex(split(keyvalue, "|"), 0), value=mvindex(split(keyvalue, "|"), 1)
| foreach ip_addresses.*.expire
    [eval mvexpire=mvappend(mvexpire, "&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;" . "|" . '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')]
| eval expire=mvindex(mvexpire, mvfind(mvexpire, "^" . replace(key, "\.", "\\.") . "\|"))
| eval expire=mvindex(split(expire, "|"), 1)
``` end ```
| table key value expire&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;key&lt;/TD&gt;&lt;TD&gt;value&lt;/TD&gt;&lt;TD&gt;expire&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10.0.0.1&lt;/TD&gt;&lt;TD&gt;some v4 ip&lt;/TD&gt;&lt;TD&gt;1749267900&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2001:53f1:3:2ee:2252:12e3:228a:112a&lt;/TD&gt;&lt;TD&gt;some v6 ip&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sun, 13 Mar 2022 05:03:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-table-using-SPATH-usage-on-simple-JSON/m-p/588838#M205070</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-03-13T05:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: SPATH usage on simple JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-table-using-SPATH-usage-on-simple-JSON/m-p/588853#M205073</link>
      <description>&lt;P&gt;Thank you very much for this!!!&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is exactly what I needed here and based on the solution, I know there's no chance I would have come even close!&lt;BR /&gt;&lt;BR /&gt;I don't have to ask questions in here too often because I can usually find a solution in another answer. So grateful for everybody that responds.&lt;/P&gt;&lt;P&gt;Thanks &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt; !&lt;/P&gt;</description>
      <pubDate>Sun, 13 Mar 2022 18:08:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-table-using-SPATH-usage-on-simple-JSON/m-p/588853#M205073</guid>
      <dc:creator>rps462</dc:creator>
      <dc:date>2022-03-13T18:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: SPATH usage on simple JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-table-using-SPATH-usage-on-simple-JSON/m-p/588856#M205075</link>
      <description>&lt;P&gt;Sorry to bother .. a few last questions on this (I hope):&lt;BR /&gt;&lt;BR /&gt;For the purposes of having some lists at the top of the list, they have a "_" in front of them. So, if in the example the list was named "_ip_address", it doesn't seem to work. I'm guessing it had something to do with:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| foreach _ip_address.*.value
    [eval keyvalue=mvappend(keyvalue, "&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;" . "|" . '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the error: Field 'keyvalue' does not exist in the data.&lt;/P&gt;&lt;P&gt;I get the same error if there are no records in a particular list. I was trying to figure out how to set it if it didn't exist, but wasn't sure where to do that.&lt;/P&gt;&lt;P&gt;Thanks again for your help.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Mar 2022 20:08:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-table-using-SPATH-usage-on-simple-JSON/m-p/588856#M205075</guid>
      <dc:creator>rps462</dc:creator>
      <dc:date>2022-03-13T20:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: SPATH usage on simple JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-table-using-SPATH-usage-on-simple-JSON/m-p/588863#M205080</link>
      <description>&lt;P&gt;In my test, whether the field name is ip_addresses or _ip_addresses, "foreach ip_addresses.*.value" matches just as well. &amp;nbsp;So, you shouldn't have to make any change. &amp;nbsp;How does it work in your case?&lt;/P&gt;&lt;P&gt;Below, one simulated event uses ip_addresses, the other _ip_addresses.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval data=mvappend("{
        \"ip_addresses\": {
                \"10.0.0.1\": {
                        \"value\": \"some v4 ip\",
                        \"expire\": 1749267900
                },
                \"2001:53f1:3:2ee:2252:12e3:228a:112a\": {
                        \"value\": \"some v6 ip\"
                }
        }
}","{
        \"_ip_addresses\": {
                \"10.0.0.2\": {
                        \"value\": \"some v4 ip\",
                        \"expire\": 1749267900
                },
                \"2001:53f1:3:2ee:2252:12e3:228a:112b\": {
                        \"value\": \"some v6 ip\"
                }
        }
}")
| mvexpand data
| rename data as _raw
| spath
``` simulate data ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The search works in both&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;key&lt;/TD&gt;&lt;TD&gt;value&lt;/TD&gt;&lt;TD&gt;expire&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="294.078125px" height="25px"&gt;10.0.0.1&lt;/TD&gt;&lt;TD width="88.59375px" height="25px"&gt;some v4 ip&lt;/TD&gt;&lt;TD width="107.015625px" height="25px"&gt;1749267900&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="294.078125px" height="25px"&gt;2001:53f1:3:2ee:2252:12e3:228a:112a&lt;/TD&gt;&lt;TD width="88.59375px" height="25px"&gt;some v6 ip&lt;/TD&gt;&lt;TD width="107.015625px" height="25px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="294.078125px" height="25px"&gt;10.0.0.2&lt;/TD&gt;&lt;TD width="88.59375px" height="25px"&gt;some v4 ip&lt;/TD&gt;&lt;TD width="107.015625px" height="25px"&gt;1749267900&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="294.078125px" height="25px"&gt;2001:53f1:3:2ee:2252:12e3:228a:112b&lt;/TD&gt;&lt;TD width="88.59375px" height="25px"&gt;some v6 ip&lt;/TD&gt;&lt;TD width="107.015625px" height="25px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(If there is neither ip_address nor _ip_address in raw data, yes, mvexpand will not have data to work with. The warning is therefore expected.)&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 02:50:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-table-using-SPATH-usage-on-simple-JSON/m-p/588863#M205080</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-03-14T02:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: SPATH usage on simple JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-table-using-SPATH-usage-on-simple-JSON/m-p/588964#M205106</link>
      <description>&lt;P&gt;Hi, thank you again for your response.&lt;/P&gt;&lt;P&gt;Generating data from a list that starts with _ seems to be ok, the error occurs after:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| foreach _ip_addresses.*.value
    [eval keyvalue=mvappend(keyvalue, "&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;" . "|" . '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')]
| mvexpand keyvalue&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specifically, it's "&lt;STRONG&gt;mvexpand keyvalue&lt;/STRONG&gt;" that generates the error, because apparently "&lt;STRONG&gt;keyvalue&lt;/STRONG&gt;" contains no data.&lt;/P&gt;&lt;P&gt;When I run this search here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval data=mvappend("{
        \"ip_addresses\": {
                \"10.0.0.1\": {
                        \"value\": \"some v4 ip\",
                        \"expire\": 1749267900
                },
                \"2001:53f1:3:2ee:2252:12e3:228a:112a\": {
                        \"value\": \"some v6 ip\"
                }
        }
}","{
        \"_ip_addresses\": {
                \"10.0.0.2\": {
                        \"value\": \"some v4 ip\",
                        \"expire\": 1749267900
                },
                \"2001:53f1:3:2ee:2252:12e3:228a:112b\": {
                        \"value\": \"some v6 ip\"
                }
        }
}")
| mvexpand data
| rename data as _raw
| spath
| foreach _ip_addresses.*.value
    [eval keyvalue=mvappend(keyvalue, "&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;" . "|" . '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')]
| mvexpand keyvalue&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the error: &lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 343px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/18486i9A3E223BB39C9829/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 17:06:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-table-using-SPATH-usage-on-simple-JSON/m-p/588964#M205106</guid>
      <dc:creator>rps462</dc:creator>
      <dc:date>2022-03-14T17:06:08Z</dc:date>
    </item>
  </channel>
</rss>

