<?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: Troubling json extraction in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Troubling-json-extraction/m-p/146242#M40833</link>
    <description>&lt;P&gt;This seems to work for me.&lt;/P&gt;

&lt;P&gt;|stats count | eval _raw="{\"status\":\"success\",\"data\":{\"11-01-00251\":\"88\",\"11-01-00247\":\"378\"}}" | rex max_match=0 "\"(?&lt;SKU&gt;[^\"]*)\":\"(?&lt;INVENTORY&gt;\d+)"&lt;/INVENTORY&gt;&lt;/SKU&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 16:30:26 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2020-09-28T16:30:26Z</dc:date>
    <item>
      <title>Troubling json extraction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Troubling-json-extraction/m-p/146238#M40829</link>
      <description>&lt;P&gt;I can't for the life of me figure this out.  There seem to be examples all over and none of them address this.&lt;/P&gt;

&lt;P&gt;I have a json element that looks like this.(I reduced the comma delimited elements to 2 for clarity, but there are dozens in the same format.&lt;BR /&gt;
{"status":"success","data":{"11-01-00251":"88","11-01-00247":"378"}}&lt;/P&gt;

&lt;P&gt;Splunk is displaying the event in structured json just fine in the event list.  What I want to do is be able to report on this data.  This is inventory.  So the first data element is the sku, and the integer is the quantity.  Basically how do I search to be able to do a &lt;/P&gt;

&lt;P&gt;|chart inventory by sku?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2014 17:38:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Troubling-json-extraction/m-p/146238#M40829</guid>
      <dc:creator>Cuyose</dc:creator>
      <dc:date>2014-04-29T17:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Troubling json extraction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Troubling-json-extraction/m-p/146239#M40830</link>
      <description>&lt;P&gt;Maybe even a regex that can extract this would be useful, Splunk's field extraction can't seem to figure it out.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2014 19:34:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Troubling-json-extraction/m-p/146239#M40830</guid>
      <dc:creator>Cuyose</dc:creator>
      <dc:date>2014-04-29T19:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: Troubling json extraction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Troubling-json-extraction/m-p/146240#M40831</link>
      <description>&lt;P&gt;You're trying to get Splunk to interpret field names as field values, which isn't easy. You might be well served to rewrite the output (either at the source, or possibly via a transform) like so:&lt;/P&gt;

&lt;P&gt;{"status":"success","data":[{"sku":"11-01-00251","inventory":"88"},{"sku":"11-01-00247","inventory":"378"}]}&lt;/P&gt;

&lt;P&gt;Then you can work with it through &lt;STRONG&gt;spath&lt;/STRONG&gt; using something like &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.3/SearchReference/Spath#Example_3:_Extract_and_expand_JSON_events_with_multvalued_fields"&gt;example 3 on the spath documentation page&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2014 15:47:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Troubling-json-extraction/m-p/146240#M40831</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2014-04-30T15:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Troubling json extraction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Troubling-json-extraction/m-p/146241#M40832</link>
      <description>&lt;P&gt;Thats what Im resorting to, I have a python script to do it and it's all done except for the little part where its adding a comma on the last data object invalidating the json.&lt;/P&gt;

&lt;P&gt;for sku in data:&lt;BR /&gt;
    print '{"sku":"'+ sku + '","count":"' + str(data[sku]) + '"},'&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2014 16:16:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Troubling-json-extraction/m-p/146241#M40832</guid>
      <dc:creator>Cuyose</dc:creator>
      <dc:date>2014-04-30T16:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Troubling json extraction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Troubling-json-extraction/m-p/146242#M40833</link>
      <description>&lt;P&gt;This seems to work for me.&lt;/P&gt;

&lt;P&gt;|stats count | eval _raw="{\"status\":\"success\",\"data\":{\"11-01-00251\":\"88\",\"11-01-00247\":\"378\"}}" | rex max_match=0 "\"(?&lt;SKU&gt;[^\"]*)\":\"(?&lt;INVENTORY&gt;\d+)"&lt;/INVENTORY&gt;&lt;/SKU&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:30:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Troubling-json-extraction/m-p/146242#M40833</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2020-09-28T16:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Troubling json extraction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Troubling-json-extraction/m-p/146243#M40834</link>
      <description>&lt;OL&gt;
&lt;LI&gt;&lt;P&gt;You might want to consider a method that does the string manipulation for a single unit of "data", and then using python's "join" command to put the results together the way you want. (I don't really know python, but that seems to be how it ought to work based on what I found on the internet.)&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Since you're adding it in as text, you might want to avoid naming the second field "count" since that's also a Splunk command.&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 30 Apr 2014 16:31:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Troubling-json-extraction/m-p/146243#M40834</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2014-04-30T16:31:15Z</dc:date>
    </item>
  </channel>
</rss>

