<?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: Nested Json dependent on a condition in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Nested-Json-dependent-on-a-condition/m-p/292366#M55694</link>
    <description>&lt;P&gt;Hi @bseifert14, is that how your JSON looks like?&lt;BR /&gt;
It's not really standard JSON and you won't be able to use the spath command with that.&lt;BR /&gt;
You need double quotes to delimit your field names and their values when non-numeric, commas to separate the key value pairs, etc.&lt;/P&gt;

&lt;P&gt;If you do have that kind of JSON, would you mind posting it here using the code sample button above (the one with 1's and 0's) so that no special characters are escaped?&lt;/P&gt;

&lt;P&gt;Then I can try to help as otherwise trying to convert your events above into standard JSON is going to take longer probably than solving your problem.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
J&lt;/P&gt;</description>
    <pubDate>Tue, 27 Mar 2018 08:20:21 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2018-03-27T08:20:21Z</dc:date>
    <item>
      <title>Nested Json dependent on a condition</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Nested-Json-dependent-on-a-condition/m-p/292365#M55693</link>
      <description>&lt;P&gt;This is my first Splunk question bear with me on my explanation..&lt;/P&gt;

&lt;P&gt;I have 70 events that all have multiple nested jsons in each event.  The framework of two events looks something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;event1:{
"tests": [
          {
          "expectation": "true"
          "reality":" true"
          "test_statistics": {
                    "components": "foo, bar"
                                        }
           }
          {
          "expectation": "true"
          "reality": "false"
          "test_statistics": {
                    "components": "foo, bar, baz"
                                        }
            }

event2:{
"tests": [
          {
          "expectation": "true"
          "reality": "true"
          "test_statistics": {
                    "components": "foo, bar, baz"
                                        }
           }
          {
          "expectation": "true"
          "reality": "true"
          "test_statistics": {
                    "components": "foo, bar"
                                        }
             }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ultimately, I want a query that will count up each component based on the fact that expectation=reality.  Therefore, my condition should be that true==true (or in other words.. expectation==reality).&lt;/P&gt;

&lt;P&gt;For my end goal I'd like to get the true tests grouped by components and the total tests grouped by components. So that, I could then generate a table that matches this format (bold is the column headers)--&amp;gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;component&lt;/STRONG&gt;  | if(&lt;STRONG&gt;True==True&lt;/STRONG&gt;)  |  &lt;STRONG&gt;Total Count&lt;/STRONG&gt;&lt;BR /&gt;
foo                         |  3                            |  4&lt;BR /&gt;
bar                         |  3                            |  4&lt;BR /&gt;
baz                         |  1                            |   4&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 16:28:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Nested-Json-dependent-on-a-condition/m-p/292365#M55693</guid>
      <dc:creator>bseifert14</dc:creator>
      <dc:date>2018-03-26T16:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Json dependent on a condition</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Nested-Json-dependent-on-a-condition/m-p/292366#M55694</link>
      <description>&lt;P&gt;Hi @bseifert14, is that how your JSON looks like?&lt;BR /&gt;
It's not really standard JSON and you won't be able to use the spath command with that.&lt;BR /&gt;
You need double quotes to delimit your field names and their values when non-numeric, commas to separate the key value pairs, etc.&lt;/P&gt;

&lt;P&gt;If you do have that kind of JSON, would you mind posting it here using the code sample button above (the one with 1's and 0's) so that no special characters are escaped?&lt;/P&gt;

&lt;P&gt;Then I can try to help as otherwise trying to convert your events above into standard JSON is going to take longer probably than solving your problem.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 08:20:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Nested-Json-dependent-on-a-condition/m-p/292366#M55694</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2018-03-27T08:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Json dependent on a condition</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Nested-Json-dependent-on-a-condition/m-p/292367#M55695</link>
      <description>&lt;P&gt;Thanks for the response Javiergn,&lt;BR /&gt;
As you directed I attempted to format as close as possible to the correct format.  Also, it should be noted that my query looks something like this to begin with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=events
            | eventstats max(_time) as maxtime
            | where _time = maxtime
            | spath path=tests{} output=tests
            | mvexpand tests
            | spath input=tests
            | makemv delim=", " test_statistics.components
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Mar 2018 13:07:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Nested-Json-dependent-on-a-condition/m-p/292367#M55695</guid>
      <dc:creator>bseifert14</dc:creator>
      <dc:date>2018-03-27T13:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Json dependent on a condition</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Nested-Json-dependent-on-a-condition/m-p/292368#M55696</link>
      <description>&lt;P&gt;OK I think I get it now.&lt;/P&gt;

&lt;P&gt;See if the following sample I tested on my lab works for you:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval events = "
{\"tests\": [
  {
      \"expectation\": \"true\",
      \"reality\":\"true\",
      \"test_statistics\": {
        \"components\": \"foo, bar\"
      }
  },
  {
      \"expectation\": \"true\",
      \"reality\": \"false\",
      \"test_statistics\": {
        \"components\": \"foo, bar, baz\"
      }
  }
]}||
{\"tests\": [
  {
      \"expectation\": \"true\",
      \"reality\":\"true\",
      \"test_statistics\": {
        \"components\": \"foo, bar, baz\"
      }
  },
  {
      \"expectation\": \"true\",
      \"reality\": \"true\",
      \"test_statistics\": {
        \"components\": \"foo, bar\"
      }
  }
]}"
| eval events = split(events, "||")
| mvexpand events
| spath input=events path=tests{} output=tests
| mvexpand tests
| spath input=tests
| rename "test_statistics.components" as component
| makemv delim="," component
| mvexpand component
| stats count(eval(match(expectation, reality))) as RealityIsExpectationCount, count as TotalCount by component
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This would be the output which I understand it is exactly what you were expecting:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/4636i60CCF6A78E2D8F68/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2018 11:01:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Nested-Json-dependent-on-a-condition/m-p/292368#M55696</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2018-03-28T11:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Json dependent on a condition</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Nested-Json-dependent-on-a-condition/m-p/292369#M55697</link>
      <description>&lt;P&gt;@bseifert14 please do not forget to accept the answer if you are happy with it&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 10:06:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Nested-Json-dependent-on-a-condition/m-p/292369#M55697</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2018-05-29T10:06:45Z</dc:date>
    </item>
  </channel>
</rss>

