<?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 json_extract returns zero results - why? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/json-extract-returns-zero-results-why/m-p/572338#M199471</link>
    <description>&lt;P&gt;I have a JSON-based log file for which every line is a valid JSON document. When searching it like this:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;source="/path/to/json/logfile" message.path="/ws/ws_metrics/page_hidden/" | table message.params.page_hide_metrics&lt;/P&gt;&lt;P&gt;I get entries with the JSON I expect, like this:&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN&gt;{"connections":[{"connection_num":1,"initialized":"2021-10-25T20:46:45.318Z","ready_state":1,"connected_duration_seconds":32.296,"ready_state_times":[null,0.512,null,null]}],"tab_session_id":"604931x|concept|1635194804","first_connection_index":0,"percent_uptime":0.9843940502316508,"duration_seconds":32.296,"page_duration_seconds":32.808}&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I try to &lt;A href="https://docs.splunk.com/Documentation/SCS/current/SearchReference/JSONFunctions#json_extract.28.26lt.3Bjson.26gt.3B.2C_.26lt.3Bpaths.26gt.3B.29" target="_self"&gt;use an example like example #1 given for json_extract in the splunk docs&lt;/A&gt;,&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;source="/path/to/json/logfile" message.path="/ws/ws_metrics/page_hidden/" | eval ph_metrics = json_extract(message.params.page_hide_metrics) | table ph_metrics&lt;/P&gt;&lt;P&gt;I don't get any results. Why?&lt;/P&gt;</description>
    <pubDate>Mon, 25 Oct 2021 20:56:57 GMT</pubDate>
    <dc:creator>codekiln</dc:creator>
    <dc:date>2021-10-25T20:56:57Z</dc:date>
    <item>
      <title>json_extract returns zero results - why?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/json-extract-returns-zero-results-why/m-p/572338#M199471</link>
      <description>&lt;P&gt;I have a JSON-based log file for which every line is a valid JSON document. When searching it like this:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;source="/path/to/json/logfile" message.path="/ws/ws_metrics/page_hidden/" | table message.params.page_hide_metrics&lt;/P&gt;&lt;P&gt;I get entries with the JSON I expect, like this:&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN&gt;{"connections":[{"connection_num":1,"initialized":"2021-10-25T20:46:45.318Z","ready_state":1,"connected_duration_seconds":32.296,"ready_state_times":[null,0.512,null,null]}],"tab_session_id":"604931x|concept|1635194804","first_connection_index":0,"percent_uptime":0.9843940502316508,"duration_seconds":32.296,"page_duration_seconds":32.808}&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I try to &lt;A href="https://docs.splunk.com/Documentation/SCS/current/SearchReference/JSONFunctions#json_extract.28.26lt.3Bjson.26gt.3B.2C_.26lt.3Bpaths.26gt.3B.29" target="_self"&gt;use an example like example #1 given for json_extract in the splunk docs&lt;/A&gt;,&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;source="/path/to/json/logfile" message.path="/ws/ws_metrics/page_hidden/" | eval ph_metrics = json_extract(message.params.page_hide_metrics) | table ph_metrics&lt;/P&gt;&lt;P&gt;I don't get any results. Why?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 20:56:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/json-extract-returns-zero-results-why/m-p/572338#M199471</guid>
      <dc:creator>codekiln</dc:creator>
      <dc:date>2021-10-25T20:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: json_extract returns zero results - why?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/json-extract-returns-zero-results-why/m-p/572358#M199478</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/165443"&gt;@codekiln&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;page_hide_metrics json element doesn't exist in payload, if you want to extract out of the payload try something like this to findout what fields being extracted.&lt;/P&gt;&lt;P&gt;If Auto KV json mode enabled you would see them extracted by default, otherwise spath helps to findout. then you can find which field to be extracted and figure out which function (json_extract) /command (spath) to use.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw="{\"connections\":[{\"connection_num\":1,\"initialized\":\"2021-10-25T20:46:45.318Z\",\"ready_state\":1,\"connected_duration_seconds\":32.296,\"ready_state_times\":[null,0.512,null,null]}],\"tab_session_id\":\"604931x|concept|1635194804\",\"first_connection_index\":0,\"percent_uptime\":0.9843940502316508,\"duration_seconds\":32.296,\"page_duration_seconds\":32.808}
" 
| spath 
| fields *&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 03:21:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/json-extract-returns-zero-results-why/m-p/572358#M199478</guid>
      <dc:creator>venkatasri</dc:creator>
      <dc:date>2021-10-26T03:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: json_extract returns zero results - why?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/json-extract-returns-zero-results-why/m-p/572480#M199526</link>
      <description>&lt;P&gt;The reason why is that field specifiers seemingly require single quotes.&amp;nbsp;I&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/SCS/current/Search/Quotations" target="_blank" rel="noopener noreferrer"&gt;found an SPL2 table of quotation marks here&lt;/A&gt;.&amp;nbsp;&lt;SPAN&gt;Apparently, single quotes are meant for field names, and double quotes are meant for string parameters to functions. &lt;/SPAN&gt;&amp;nbsp;My hypothesis is that SPL lets one use fields with dotted delimiters in certain parts of queries such as at the beginning, but not when passing a reference to fields in a function.&lt;/P&gt;&lt;P&gt;To solve, use single quotes around the field specifier. &lt;SPAN&gt;So this will return the entire JSON object:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;source="/path/to/json/logfile" message.path="/ws/ws_metrics/page_hidden/" | eval ph_metrics = json_extract('message.params.page_hide_metrics') | table ph_metrics&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And this will return just the connections attribute within the JSON:&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="markup"&gt;source="/path/to/json/logfile" message.path="/ws/ws_metrics/page_hidden/" | eval ph_metrics=json_extract('message.params.page_hide_metrics', "connections{}") | table ph_metrics&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 18:26:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/json-extract-returns-zero-results-why/m-p/572480#M199526</guid>
      <dc:creator>codekiln</dc:creator>
      <dc:date>2021-10-26T18:26:45Z</dc:date>
    </item>
  </channel>
</rss>

