<?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 Splunk REST api to retrieve proper JSON using Python? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-REST-api-to-retrieve-proper-JSON-using-Python/m-p/500178#M8982</link>
    <description>&lt;P&gt;Team&lt;/P&gt;
&lt;P&gt;I am able to make a POST call to export end point and getting the search results. I am using Python requests library.&lt;BR /&gt;The result is not in proper Json. It returns multiple JSON with preview object. I would like to know how to avoid "preview" to be returned from the response. OR how to overcome the below error? I guess the error is due to the response not in proper Json format.&lt;BR /&gt;Appreciate any pointers.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Here is the &lt;STRONG&gt;&lt;EM&gt;code snippet.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;response = requests.post(URL, data=xxxx, headers=headers,verify=False)&lt;BR /&gt;print("Status = "+str(response.status_code) )&lt;BR /&gt;print("response text = "+str(response.text))&lt;BR /&gt;json_data = json.loads(str(r.text))&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Sample output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;response text = {"preview":true,"offset":0,"lastrow":true,"result":{"_time":"2019-10-09 21:12:00.131 UTC","event_guid":"xxxxxxx","event_category":"WEB","event_workflow":"xxxxx","event_subcategory":"xxxxx"}}&lt;BR /&gt;{"preview":true,"offset":0,"lastrow":true,"result":{"_time":"2019-10-09 21:36:06.752 UTC","event_guid":"xxxxxxx-","event_category":"WEB","event_workflow":"xxxxx","event_subcategory":"xxxx"}}&lt;BR /&gt;{"preview":false,"offset":0,"result":{"_time":"2019-10-09 21:12:00.131 UTC","event_guid":"xxxx-","event_category":"WEB","event_workflow":"xxxx","event_subcategory":"xxxxx"}}&lt;/P&gt;
&lt;P&gt;and so on.. The last command json.loads gives the below error:&lt;BR /&gt;I tried without str(). still not working.&lt;BR /&gt;&lt;STRONG&gt;Extra data: line 2 column 1 (char 219)&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Nov 2022 13:52:32 GMT</pubDate>
    <dc:creator>rajeswarija</dc:creator>
    <dc:date>2022-11-15T13:52:32Z</dc:date>
    <item>
      <title>Splunk REST api to retrieve proper JSON using Python?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-REST-api-to-retrieve-proper-JSON-using-Python/m-p/500178#M8982</link>
      <description>&lt;P&gt;Team&lt;/P&gt;
&lt;P&gt;I am able to make a POST call to export end point and getting the search results. I am using Python requests library.&lt;BR /&gt;The result is not in proper Json. It returns multiple JSON with preview object. I would like to know how to avoid "preview" to be returned from the response. OR how to overcome the below error? I guess the error is due to the response not in proper Json format.&lt;BR /&gt;Appreciate any pointers.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Here is the &lt;STRONG&gt;&lt;EM&gt;code snippet.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;response = requests.post(URL, data=xxxx, headers=headers,verify=False)&lt;BR /&gt;print("Status = "+str(response.status_code) )&lt;BR /&gt;print("response text = "+str(response.text))&lt;BR /&gt;json_data = json.loads(str(r.text))&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Sample output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;response text = {"preview":true,"offset":0,"lastrow":true,"result":{"_time":"2019-10-09 21:12:00.131 UTC","event_guid":"xxxxxxx","event_category":"WEB","event_workflow":"xxxxx","event_subcategory":"xxxxx"}}&lt;BR /&gt;{"preview":true,"offset":0,"lastrow":true,"result":{"_time":"2019-10-09 21:36:06.752 UTC","event_guid":"xxxxxxx-","event_category":"WEB","event_workflow":"xxxxx","event_subcategory":"xxxx"}}&lt;BR /&gt;{"preview":false,"offset":0,"result":{"_time":"2019-10-09 21:12:00.131 UTC","event_guid":"xxxx-","event_category":"WEB","event_workflow":"xxxx","event_subcategory":"xxxxx"}}&lt;/P&gt;
&lt;P&gt;and so on.. The last command json.loads gives the below error:&lt;BR /&gt;I tried without str(). still not working.&lt;BR /&gt;&lt;STRONG&gt;Extra data: line 2 column 1 (char 219)&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 13:52:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-REST-api-to-retrieve-proper-JSON-using-Python/m-p/500178#M8982</guid>
      <dc:creator>rajeswarija</dc:creator>
      <dc:date>2022-11-15T13:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk REST api to retrieve proper JSON using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-REST-api-to-retrieve-proper-JSON-using-Python/m-p/620866#M10843</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/211805"&gt;@rajeswarija&lt;/a&gt;&amp;nbsp;did you solve this issue? i have the same problem&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 10:01:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-REST-api-to-retrieve-proper-JSON-using-Python/m-p/620866#M10843</guid>
      <dc:creator>jim05</dc:creator>
      <dc:date>2022-11-15T10:01:47Z</dc:date>
    </item>
  </channel>
</rss>

