<?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: Why is the Splunk Python SDK not returning formatted numbers in the JSON response? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-Splunk-Python-SDK-not-returning-formatted-numbers-in/m-p/219682#M43124</link>
    <description>&lt;P&gt;Splunk should honor that data type in the json response if I specify the data type in the search query. &lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Lp&lt;/P&gt;</description>
    <pubDate>Fri, 22 Apr 2016 11:40:00 GMT</pubDate>
    <dc:creator>lpolo</dc:creator>
    <dc:date>2016-04-22T11:40:00Z</dc:date>
    <item>
      <title>Why is the Splunk Python SDK not returning formatted numbers in the JSON response?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-Splunk-Python-SDK-not-returning-formatted-numbers-in/m-p/219680#M43122</link>
      <description>&lt;P&gt;Splunk Python SDK does not return formatted numbers in the JSON response.&lt;/P&gt;

&lt;P&gt;Example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval var1=tonumber(var2)|
table var1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[{"var1": "321"}]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I was expecting&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[{"var1": 321}]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any idea why?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Lp&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2016 16:47:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-Splunk-Python-SDK-not-returning-formatted-numbers-in/m-p/219680#M43122</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2016-04-21T16:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the Splunk Python SDK not returning formatted numbers in the JSON response?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-Splunk-Python-SDK-not-returning-formatted-numbers-in/m-p/219681#M43123</link>
      <description>&lt;P&gt;I'm not working at Splunk so I can't really answer the why. However, it looks like Splunk is unaware of the data type (which makes sense given that the data type is figured out on search time). I'm guessing this is the reason everything is quoted in the JSON response, to prevent invalid JSON.&lt;/P&gt;

&lt;P&gt;It's not very hard to work around this in Python (although there might be a minor performance hit). Try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def parseDictValues(d):
    for key, value in d.iteritems():

        # Test for a float
        try:
            d[key] = float(value)
        except ValueError:
            pass
    return d
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then loop through the results you've received and call this function to convert all numeric values.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 07:35:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-Splunk-Python-SDK-not-returning-formatted-numbers-in/m-p/219681#M43123</guid>
      <dc:creator>gwobben</dc:creator>
      <dc:date>2016-04-22T07:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the Splunk Python SDK not returning formatted numbers in the JSON response?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-Splunk-Python-SDK-not-returning-formatted-numbers-in/m-p/219682#M43124</link>
      <description>&lt;P&gt;Splunk should honor that data type in the json response if I specify the data type in the search query. &lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Lp&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 11:40:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-Splunk-Python-SDK-not-returning-formatted-numbers-in/m-p/219682#M43124</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2016-04-22T11:40:00Z</dc:date>
    </item>
  </channel>
</rss>

