<?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: Parse nested JSON where the object names are different in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Parse-nested-JSON-where-the-object-names-are-different/m-p/479267#M82255</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;...
| spath path=data{} output=data
| spath path=status
| mvexpand data
| eval data=replace(data, "Event\d", "Events")
| spath input=data
| rename Events{}.* as *
| fields - Events
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;same way&lt;/P&gt;</description>
    <pubDate>Wed, 22 Apr 2020 21:56:23 GMT</pubDate>
    <dc:creator>to4kawa</dc:creator>
    <dc:date>2020-04-22T21:56:23Z</dc:date>
    <item>
      <title>Parse nested JSON where the object names are different</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Parse-nested-JSON-where-the-object-names-are-different/m-p/479264#M82252</link>
      <description>&lt;P&gt;I have this application log that is made up of nested JSON&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
  "status": "OK",
  "next": null,
  "data": {
    "Event1": {
      "Time": "2020-04-21 11:28:22",
      "Username": "testuser11@test.com",
      "IP_Address": "127.0.0.1",
      "Action": "Log in",
      "Data": "12.34.56.78"
    },
    "Event2": {
      "Time": "2020-04-21 11:26:41",
      "Username": "testuser2@test.com",
      "IP_Address": "127.0.0.1",
      "Action": "Log in",
      "Data": "23.45.67.89"
    },
    "Event3": {
      "Time": "2020-04-21 11:25:37",
      "Username": "testuser3@test.com",
      "IP_Address": "127.0.0.1",
      "Action": "Log in",
      "Data": "34.123.56.78"
    }
  }
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to try to search on Username (or really any of the fields under the "Event &lt;EM&gt;x&lt;/EM&gt;" key field).&lt;BR /&gt;
My issue is that the application increments the Event number so I can't do a normal &lt;EM&gt;spath path=data.Event{}.Username&lt;/EM&gt; statement.&lt;/P&gt;

&lt;P&gt;I am not skilled enough in the ways of &lt;EM&gt;spath&lt;/EM&gt; or the  &lt;EM&gt;rename|mvzip|mvexpand|mvindex&lt;/EM&gt; combonations to figure this out.  I feel the answer is to do something like that, but that is just from reading all of the other Answers that had JSON parsing issues.  Please help.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 13:38:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Parse-nested-JSON-where-the-object-names-are-different/m-p/479264#M82252</guid>
      <dc:creator>randy_moore</dc:creator>
      <dc:date>2020-04-22T13:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: Parse nested JSON where the object names are different</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Parse-nested-JSON-where-the-object-names-are-different/m-p/479265#M82253</link>
      <description>&lt;P&gt;What about something like this: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval testdata="{
   \"status\": \"OK\",
   \"next\": null,
   \"data\": {
     \"Event1\": {
       \"Time\": \"2020-04-21 11:28:22\",
       \"Username\": \"testuser11@test.com\",
       \"IP_Address\": \"127.0.0.1\",
       \"Action\": \"Log in\",
       \"Data\": \"12.34.56.78\"
         },
     \"Event2\": {
       \"Time\": \"2020-04-21 11:26:41\",
       \"Username\": \"testuser2@test.com\",
       \"IP_Address\": \"127.0.0.1\",
       \"Action\": \"Log in\",
       \"Data\": \"23.45.67.89\"
         },
     \"Event3\": {
       \"Time\": \"2020-04-21 11:25:37\",
       \"Username\": \"testuser3@test.com\",
       \"IP_Address\": \"127.0.0.1\",
       \"Action\": \"Log in\",
       \"Data\": \"34.123.56.78\"
         }
   }
 }" 
| rename testdata AS _raw 
| rex field=_raw "\"Event(?&amp;lt;eventcount&amp;gt;\d+)\"\:\s\{[^\}]+\}\s+\}\s+\}" 
| rex field=_raw max_match=0 "\"Event(\d+)\"\:\s(?&amp;lt;events&amp;gt;\{[^\}]+\})" 
| spath 
| table _raw events eventcount status next 
| mvexpand events
| spath input=events
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which puts each event on its own to enumerate by itself . &lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 15:24:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Parse-nested-JSON-where-the-object-names-are-different/m-p/479265#M82253</guid>
      <dc:creator>darrenfuller</dc:creator>
      <dc:date>2020-04-22T15:24:04Z</dc:date>
    </item>
    <item>
      <title>Re: Parse nested JSON where the object names are different</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Parse-nested-JSON-where-the-object-names-are-different/m-p/479266#M82254</link>
      <description>&lt;P&gt;Thanks @darrenfuller !  That  was a great help.    I had to modify the rex a little bit to account for my exact specific data.  That gave me the opportunity to dive into regex and figure out what you wrote.  Once I did that, I was able to get it working just like your example.&lt;/P&gt;

&lt;P&gt;Thanks again!&lt;/P&gt;

&lt;P&gt;Randy&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 21:28:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Parse-nested-JSON-where-the-object-names-are-different/m-p/479266#M82254</guid>
      <dc:creator>randy_moore</dc:creator>
      <dc:date>2020-04-22T21:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: Parse nested JSON where the object names are different</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Parse-nested-JSON-where-the-object-names-are-different/m-p/479267#M82255</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;...
| spath path=data{} output=data
| spath path=status
| mvexpand data
| eval data=replace(data, "Event\d", "Events")
| spath input=data
| rename Events{}.* as *
| fields - Events
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;same way&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 21:56:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Parse-nested-JSON-where-the-object-names-are-different/m-p/479267#M82255</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-04-22T21:56:23Z</dc:date>
    </item>
  </channel>
</rss>

