<?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: How to handle simple JSON array with spath in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103179#M21682</link>
    <description>&lt;P&gt;Hey Guys,, when you use 'foo' everywhere, its a little difficult for me to follow which refers to which 'foo'.. Please use variants like 'foo2' or 'foo_key' etc for clarity for beginners &lt;/P&gt;</description>
    <pubDate>Sun, 09 Aug 2015 15:26:46 GMT</pubDate>
    <dc:creator>sivasn1</dc:creator>
    <dc:date>2015-08-09T15:26:46Z</dc:date>
    <item>
      <title>How to handle simple JSON array with spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103174#M21677</link>
      <description>&lt;P&gt;The field value is &lt;CODE&gt;["","apples","oranges"]&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| spath input=foo&lt;/CODE&gt; creates a multi-value field named '{}'. which is a little weird.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| spath input=foo output=bar&lt;/CODE&gt; fails. splunk complains &lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Error in 'spath' command: You have not specified a path. Try using "path=mypath" as an argument to spath.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;I can't find a value for path that works, given that i want to address the root.&lt;/P&gt;

&lt;P&gt;A kludgey workaround is &lt;CODE&gt;| spath input=foo | rename "{}" AS bar&lt;/CODE&gt;, but it would be nicer if this was possible with spath alone.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Oct 2012 20:16:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103174#M21677</guid>
      <dc:creator>ruman</dc:creator>
      <dc:date>2012-10-25T20:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle simple JSON array with spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103175#M21678</link>
      <description>&lt;P&gt;Are you sure that you are feeding it proper json formated data? I did some stuff with json that wasn't working quite right and it turned out we were not formating it correctly.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Oct 2012 21:30:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103175#M21678</guid>
      <dc:creator>gryz</dc:creator>
      <dc:date>2012-10-25T21:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle simple JSON array with spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103176#M21679</link>
      <description>&lt;P&gt;The fact that &lt;CODE&gt;spath input=foo&lt;/CODE&gt; correctly creates a multiple value field, with correct data, suggests that the JSON is well-formed.&lt;/P&gt;

&lt;P&gt;As noted, the JSON in question is &lt;CODE&gt;["","apples","oranges"]&lt;/CODE&gt; - let me know if there's something wrong with that. Maybe I should provide the original event:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;[25-Oct-2012 13:37:38] INFO [test] foo="[\"\",\"apples\",\"oranges\"]"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;There's a transform that handles the escaped quotes gracefully.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Oct 2012 21:46:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103176#M21679</guid>
      <dc:creator>ruman</dc:creator>
      <dc:date>2012-10-25T21:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle simple JSON array with spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103177#M21680</link>
      <description>&lt;P&gt;This might not answer your question, but I had a similar problem getting spath to work with an array of objects. For &lt;CODE&gt;foo=[{"bar":1},{"bar":2},{"bar":3}]&lt;/CODE&gt;, I did not even get a multivalued field named '{}' when using: &lt;CODE&gt;| spath input=foo&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I got spath to work by changing my log format and wrapping the JSON array in an object:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foo={"foo":[{"bar":1},{"bar":2},{"bar":3}]}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I was then able to use the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| spath input=foo output=bar path=foo{}.bar
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Without altering the log, I was able to use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval foo="{\"foo\":" + foo + "}" | spath input=foo output=bar path=foo{}.bar
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Feb 2013 23:41:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103177#M21680</guid>
      <dc:creator>vliao</dc:creator>
      <dc:date>2013-02-11T23:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle simple JSON array with spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103178#M21681</link>
      <description>&lt;P&gt;Wow! That's perfect. For my case, just a naked array instead of an array of objects, I was able to say&lt;/P&gt;

&lt;P&gt;foo=["","apples","oranges"]&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval foo="{\"foo\":" + foo + "}" | spath input=foo output=bar path=foo{}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2013 01:01:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103178#M21681</guid>
      <dc:creator>ruman</dc:creator>
      <dc:date>2013-02-15T01:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle simple JSON array with spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103179#M21682</link>
      <description>&lt;P&gt;Hey Guys,, when you use 'foo' everywhere, its a little difficult for me to follow which refers to which 'foo'.. Please use variants like 'foo2' or 'foo_key' etc for clarity for beginners &lt;/P&gt;</description>
      <pubDate>Sun, 09 Aug 2015 15:26:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103179#M21682</guid>
      <dc:creator>sivasn1</dc:creator>
      <dc:date>2015-08-09T15:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle simple JSON array with spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103180#M21683</link>
      <description>&lt;P&gt;How do I extract the title information from the json and table it &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[{
    'start_time': '2016-08-05T18:42:00Z',
    'title': u "event1",
    'end_time': '2016-08-05T20:49:00Z'
}, {
    'start_time': '2016-08-05T18:42:00Z',
    'title': u "event2",
    'end_time': '2016-08-05T20:49:00Z'
}]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Desired output (in table)&lt;BR /&gt;
Title&lt;BR /&gt;
event1&lt;BR /&gt;
event2&lt;/P&gt;

&lt;P&gt;Here is the search I have and it doesn't work&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| spath input=err output=title path={}.title | table title
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Aug 2016 17:36:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103180#M21683</guid>
      <dc:creator>sheshank_kodam</dc:creator>
      <dc:date>2016-08-04T17:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle simple JSON array with spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103181#M21684</link>
      <description>&lt;P&gt;&lt;A href="https://en.wikipedia.org/wiki/Metasyntactic_variable#English"&gt;https://en.wikipedia.org/wiki/Metasyntactic_variable#English&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 21:29:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103181#M21684</guid>
      <dc:creator>ruman_splunk</dc:creator>
      <dc:date>2016-08-04T21:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle simple JSON array with spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103182#M21685</link>
      <description>&lt;P&gt;@sivasn1 -&lt;/P&gt;

&lt;P&gt;The event JSON comes in with this data...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  foo1=["","apples","oranges"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This takes the value above, prepends the name &lt;CODE&gt;foo3&lt;/CODE&gt; to it to establish a valid path in JSON format, and puts it into a variable named &lt;CODE&gt;foo2&lt;/CODE&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eval foo2="{\"foo3\":" + foo1 + "}" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This takes the &lt;CODE&gt;foo2&lt;/CODE&gt; valid JSON variable we just created value above, and uses the &lt;CODE&gt;spath&lt;/CODE&gt; command to tell it to extract the information from down the &lt;CODE&gt;foo3&lt;/CODE&gt; path to a normal splunk multivalue field named &lt;CODE&gt;foo4&lt;/CODE&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| spath input=foo2 output=foo4 path=foo3{}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Using the above, you should be able to understand what was happening with the original code.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Here's a run-anywhere sample...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | makeresults 
 | eval foo1="[\"\",\"apples\",\"oranges\"]"
 | eval foo2="{\"foo3\":" + foo1 + "}" 
 | spath input=foo2 output=foo4 path=foo3{}
 | table foo1 foo2 foo3 foo4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note that with the above table command, field &lt;CODE&gt;foo3&lt;/CODE&gt; will be null, because it isn't a field in splunk, it is a field name assigned solely in the JSON data.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 20:24:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103182#M21685</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-03-01T20:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle simple JSON array with spath</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103183#M21686</link>
      <description>&lt;P&gt;&lt;STRONG&gt;*How to use spath for below JSON to check if for AnalyticsExternalDataSizeMB Remaining/Max*100 is &amp;gt;=70%?&lt;/STRONG&gt;*&lt;/P&gt;

&lt;P&gt;{&lt;BR /&gt;
   "AnalyticsExternalDataSizeMB":{&lt;BR /&gt;
      "Max":478600,&lt;BR /&gt;
      "Remaining":40960&lt;BR /&gt;
   },&lt;BR /&gt;
   "ConcurrentAsyncGetReportInstances":{&lt;BR /&gt;
      "Max":200,&lt;BR /&gt;
      "Remaining":200&lt;BR /&gt;
   },&lt;BR /&gt;
   "ConcurrentEinsteinDataInsightsStoryCreation":{&lt;BR /&gt;
      "Max":5,&lt;BR /&gt;
      "Remaining":5&lt;BR /&gt;
   },&lt;BR /&gt;
   "ConcurrentEinsteinDiscoveryStoryCreation":{&lt;BR /&gt;
      "Max":2,&lt;BR /&gt;
      "Remaining":2&lt;BR /&gt;
   },&lt;BR /&gt;
   "ConcurrentSyncReportRuns":{&lt;BR /&gt;
      "Max":20,&lt;BR /&gt;
      "Remaining":20&lt;BR /&gt;
   },&lt;BR /&gt;
   "DailyAnalyticsDataflowJobExecutions":{&lt;BR /&gt;
      "Max":60,&lt;BR /&gt;
      "Remaining":60&lt;BR /&gt;
   },&lt;BR /&gt;
   "DailyAnalyticsUploadedFilesSizeMB":{&lt;BR /&gt;
      "Max":51200,&lt;BR /&gt;
      "Remaining":51200&lt;BR /&gt;
   },&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 05:21:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-handle-simple-JSON-array-with-spath/m-p/103183#M21686</guid>
      <dc:creator>sanjax90</dc:creator>
      <dc:date>2020-09-30T05:21:42Z</dc:date>
    </item>
  </channel>
</rss>

