<?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: Fetch data from json string[] in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Fetch-data-from-json-string/m-p/509482#M142384</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/184221"&gt;@to4kawa&lt;/a&gt;&amp;nbsp;Much cleaner approach, I will try to explore more of&amp;nbsp;spath().&lt;/P&gt;</description>
    <pubDate>Thu, 16 Jul 2020 09:40:25 GMT</pubDate>
    <dc:creator>vickycoder27</dc:creator>
    <dc:date>2020-07-16T09:40:25Z</dc:date>
    <item>
      <title>Fetch data from json string[]</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Fetch-data-from-json-string/m-p/509297#M142319</link>
      <description>&lt;P&gt;I have a curl response which is json string[], I am able to fetch the data using split(), mvexpand() and then substring. But the problem with substring is, if the sequence of value for a key changes then result is not correct. Tried mvindex on the manipulated data but it doesn't work or rex, not sure if I am doing any thing wrong.&lt;/P&gt;&lt;P&gt;Below is my log and I am interested in "Response []" from which I want to pull&amp;nbsp;userId i.e. 9401850890,&amp;nbsp;9801850840,&amp;nbsp;9801850841.&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;&lt;EM&gt;APIName=TestApi, HTTP_STATUS=200, totalTime=2346, Response=[{"id":11168715,"state":"Open","title":"TESTS NOTIFICATION - SPIKE IN USEAGE userId : 9401850890"},{"id":11168716,"state":"Closed","title":"TESTS NOTIFICATION - SPIKE IN USEAGE userId : 9801850840"},{"id":21172617,"state":"Verify","title":"TESTS NOTIFICATION - SPIKE IN USEAGE userId : 9801850841"}]&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Query that I tried :&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;index=api_stats source=apistats earliest=-10m@m latest=-0m@m | eval x=ltrim(Response,“[”) | eval n=rtrim(x, “]”) | eval temp=split(n,“}”)| mvexpand temp| eval y=ltrim(temp,“,”) | eval testData=mvindex(y,-1) | eval testId=substr(testData, 7, 9)| eval apiCallerID=substr(testData, 92, 10) | table testData,testId,apiCallerID&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2020 13:13:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Fetch-data-from-json-string/m-p/509297#M142319</guid>
      <dc:creator>vickycoder27</dc:creator>
      <dc:date>2020-07-15T13:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch data from json string[]</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Fetch-data-from-json-string/m-p/509351#M142339</link>
      <description>&lt;P&gt;Perhaps this will help.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval Response="[{\"id\":11168715,\"state\":\"Open\",\"title\":\"TESTS NOTIFICATION - SPIKE IN USEAGE userId : 9401850890\"},{\"id\":11168716,\"state\":\"Closed\",\"title\":\"TESTS NOTIFICATION - SPIKE IN USEAGE userId : 9801850840\"},{\"id\":21172617,\"state\":\"Verify\",\"title\":\"TESTS NOTIFICATION - SPIKE IN USEAGE userId : 9801850841\"}]"
```Above just creates test data```
| eval x=ltrim(Response,"[") 
| eval n=rtrim(x, "]") 
| eval temp=split(n,"}") 
| mvexpand temp 
| eval y=ltrim(temp,",") 
| eval testData=mvindex(y,-1) 
| rex field=testData "id\":(?&amp;lt;testId&amp;gt;\d+)"
| rex field=testData "userId\s:\s(?&amp;lt;apiCallerID&amp;gt;\d+)"
| table testData,testId,apiCallerID&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 15 Jul 2020 16:41:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Fetch-data-from-json-string/m-p/509351#M142339</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-07-15T16:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch data from json string[]</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Fetch-data-from-json-string/m-p/509403#M142359</link>
      <description>&lt;LI-CODE lang="markup"&gt;index=_internal |head 1 | table _raw _time | eval _raw="APIName=TestApi, HTTP_STATUS=200, totalTime=2346, Response=[{\"id\":11168715,\"state\":\"Open\",\"title\":\"TESTS NOTIFICATION - SPIKE IN USEAGE userId : 9401850890\"},{\"id\":11168716,\"state\":\"Closed\",\"title\":\"TESTS NOTIFICATION - SPIKE IN USEAGE userId : 9801850840\"},{\"id\":21172617,\"state\":\"Verify\",\"title\":\"TESTS NOTIFICATION - SPIKE IN USEAGE userId : 9801850841\"}]"
| kv
| spath input=Response {} output=response
| stats count by response
| spath input=response
| fields - count response&lt;/LI-CODE&gt;&lt;P&gt;how about this?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2020 20:45:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Fetch-data-from-json-string/m-p/509403#M142359</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-07-15T20:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch data from json string[]</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Fetch-data-from-json-string/m-p/509482#M142384</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/184221"&gt;@to4kawa&lt;/a&gt;&amp;nbsp;Much cleaner approach, I will try to explore more of&amp;nbsp;spath().&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jul 2020 09:40:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Fetch-data-from-json-string/m-p/509482#M142384</guid>
      <dc:creator>vickycoder27</dc:creator>
      <dc:date>2020-07-16T09:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch data from json string[]</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Fetch-data-from-json-string/m-p/636079#M220944</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I would only suggest a change in the query. change this line | eval temp=split(n,"}") by | eval temp=split(n,"},"). So when assembling a graph, for example, it avoids adding an empty column, for example.&amp;nbsp;Just to clarify, this query saved me, thank you very much.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 00:25:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Fetch-data-from-json-string/m-p/636079#M220944</guid>
      <dc:creator>flavioweb1</dc:creator>
      <dc:date>2023-03-27T00:25:34Z</dc:date>
    </item>
  </channel>
</rss>

