<?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 How to parse JSON log data? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121521#M25194</link>
    <description>&lt;P&gt;I created an input in the _json format and send to it httpd access logs.&lt;BR /&gt;
I received such logs:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Jul 14 14:35:44 172.16.16.100 1 2015-07-14T14:35:44+03:00 us-.local httpd - - - {"PROGRAM":"httpd","LOGTYPE":"access","ISODATE":"2015-07-14T14:35:44+03:00","HTTP":{"VHOST":"..com","USER_AGENT":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36","STATUS":"200","SIZE":"21","REQUEST_TIME":"756174","REQUEST":"GET /admins/widget/?widget_ReplicationLag_yw1[]= HTTP/1.1","REMOTE_USER":"u.","REMOTE_ADDR":"","REFERER":"https://..com/invoices/index","DATE":"2015-07-14T14:35:44"},"HOST_FROM":"us-.local","HOST":"us-.local","FILE_NAME":"/var/run/syslog-ng/apache.access.fifo"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How I can parse this logs? &lt;/P&gt;</description>
    <pubDate>Tue, 14 Jul 2015 11:40:56 GMT</pubDate>
    <dc:creator>vinchakov_a</dc:creator>
    <dc:date>2015-07-14T11:40:56Z</dc:date>
    <item>
      <title>How to parse JSON log data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121521#M25194</link>
      <description>&lt;P&gt;I created an input in the _json format and send to it httpd access logs.&lt;BR /&gt;
I received such logs:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Jul 14 14:35:44 172.16.16.100 1 2015-07-14T14:35:44+03:00 us-.local httpd - - - {"PROGRAM":"httpd","LOGTYPE":"access","ISODATE":"2015-07-14T14:35:44+03:00","HTTP":{"VHOST":"..com","USER_AGENT":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36","STATUS":"200","SIZE":"21","REQUEST_TIME":"756174","REQUEST":"GET /admins/widget/?widget_ReplicationLag_yw1[]= HTTP/1.1","REMOTE_USER":"u.","REMOTE_ADDR":"","REFERER":"https://..com/invoices/index","DATE":"2015-07-14T14:35:44"},"HOST_FROM":"us-.local","HOST":"us-.local","FILE_NAME":"/var/run/syslog-ng/apache.access.fifo"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How I can parse this logs? &lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2015 11:40:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121521#M25194</guid>
      <dc:creator>vinchakov_a</dc:creator>
      <dc:date>2015-07-14T11:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse JSON log data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121522#M25195</link>
      <description>&lt;P&gt;Partially I understood. I created new field extraction and doing:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=_json | eval _raw = access_log_json | spath
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But how can I execute all before {  on the input step????&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2015 12:06:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121522#M25195</guid>
      <dc:creator>vinchakov_a</dc:creator>
      <dc:date>2015-07-14T12:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse JSON log data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121523#M25196</link>
      <description>&lt;P&gt;So what you have here is not a JSON log event.  You have a plaintext log event which happens to contain JSON.  That's a BIG difference.  &lt;/P&gt;

&lt;P&gt;It looks like these are coming through a syslog server which is prepending data before the JSON blob.  If you don't need that data (as at least some of it looks redundant) then it would help if you could alter your syslog config for this file to not prepend the raw text and just write the JSON portion.  If the event is &lt;EM&gt;just&lt;/EM&gt; JSON, splunk will parse it automatically.  &lt;/P&gt;

&lt;P&gt;Failing that, you can handle this at search time: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval rex "(?P&amp;lt;json_data&amp;gt;{.*})" | spath input=json_data
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jul 2015 19:30:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121523#M25196</guid>
      <dc:creator>emiller42</dc:creator>
      <dc:date>2015-07-14T19:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse JSON log data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121524#M25197</link>
      <description>&lt;P&gt;I understood that it not absolutely json. I could process it as wrote above to comments. It is possible to cut off a log on reception? before events creating&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 04:24:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121524#M25197</guid>
      <dc:creator>vinchakov_a</dc:creator>
      <dc:date>2015-07-15T04:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse JSON log data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121525#M25198</link>
      <description>&lt;P&gt;You can use index-time transforms to rewrite the event before it's written to the index.  But you lose the prepending data.  &lt;/P&gt;

&lt;P&gt;In transforms.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[my_data_json_extraction]
SOURCE_KEY = _raw
DEST_KEY = _raw
REGEX = ^([^{]+)({.+})$
FORMAT = $2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In props.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[my_sourcetype]
KV_MODE = json
TRANSFORMS-whatever = my_data_json_extraction
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The name of the transforms stanza can be whatever you want.  It just needs to be unique.   Same for the &lt;CODE&gt;TRANSFORMS-foo&lt;/CODE&gt; bit in props.  Just make the part after &lt;CODE&gt;TRANSFORMS-&lt;/CODE&gt; unique.  &lt;/P&gt;

&lt;P&gt;I highly recommend testing this locally before applying it to production data as it is destructive.  Make sure you capture anything you need from the initial part of the logs before applying this.  &lt;/P&gt;

&lt;P&gt;Reference the documentation for &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Admin/Propsconf"&gt;props.conf&lt;/A&gt; and &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Admin/Transformsconf"&gt;transforms.conf&lt;/A&gt; for details.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 14:51:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121525#M25198</guid>
      <dc:creator>emiller42</dc:creator>
      <dc:date>2015-07-15T14:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse JSON log data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121526#M25199</link>
      <description>&lt;P&gt;It's cool!!!! It works! Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2015 08:24:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121526#M25199</guid>
      <dc:creator>vinchakov_a</dc:creator>
      <dc:date>2015-07-17T08:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse JSON log data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121527#M25200</link>
      <description>&lt;P&gt;Glad this worked for you!  Can you accept the answer so others know there's a solution here?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2015 22:14:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-JSON-log-data/m-p/121527#M25200</guid>
      <dc:creator>emiller42</dc:creator>
      <dc:date>2015-07-20T22:14:19Z</dc:date>
    </item>
  </channel>
</rss>

