<?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 parse a JSON from REST API? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-a-JSON-from-REST-API/m-p/428309#M75047</link>
    <description>&lt;P&gt;Quick update, everything was resolved by using the out of the box _json sourcetype. Not sure why I was complicating my life...&lt;/P&gt;</description>
    <pubDate>Sat, 07 Jul 2018 12:02:55 GMT</pubDate>
    <dc:creator>claudio_palmeri</dc:creator>
    <dc:date>2018-07-07T12:02:55Z</dc:date>
    <item>
      <title>How to parse a JSON from REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-a-JSON-from-REST-API/m-p/428305#M75043</link>
      <description>&lt;P&gt;Hi all,&lt;BR /&gt;
I need some help parsing a JSON containing none/one/multiple nested messages that I have imported via REST API (poll). I am saying one or multiple or none as it depends on what the poll is retrieving from the REST API. &lt;/P&gt;

&lt;P&gt;In the event that the poll is retrieving no new events, I would like Splunk not to show an empty entry (square brackets only) in the log. In the event of a single message, I'd like to remove the header/footer (square brackets) and display the event. In the event of multiple messages, I would like Splunk to remove header/footer as well as split the message in individual events, with associated timestamp.&lt;/P&gt;

&lt;P&gt;I have been doing a lot of research, however I am struggling with the various attributes in $SPLUNK_HOME/etc/system/local/props.conf and with the related regular expressions to make the whole thing work.&lt;/P&gt;

&lt;P&gt;A sample JSON with three messages is below.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[
    {
        "source": "APPNAME",
        "id": "1234567890",
        "recorded": "2018-06-07T00:44:22.584Z",
        "action": null,
        "actors": [
            {
                "type": "user",
                "name": "email1@domain.com",
                "id": null
            }
        ],
        "resources": [],
        "client": null,
        "result": {
            "status": "SUCCESS",
            "message": "message1"
        }
    },
    {
        "source": "APPNAME",
        "id": "2345678901",
        "recorded": "2018-05-07T05:12:47.409Z",
        "action": null,
        "actors": [
            {
                "type": "user",
                "name": "email2@domain.com",
                "id": null
            }
        ],
        "resources": [],
        "client": null,
        "result": {
            "status": "POLICY",
            "message": "Details:\nIP Address: 222.222.222.222\nCountry: AU\nNew Device: true \"Default Action\"\n"
        }
    },
    {
        "source": "APPNAME",
        "id": "3456789012",
        "recorded": "2018-05-07T05:12:58.137Z",
        "action": null,
        "actors": [
            {
                "type": "user",
                "name": "email3@domain.com",
                "id": null
            }
        ],
        "resources": [],
        "client": null,
        "result": {
            "status": "SUCCESS",
            "message": "message3"
        }
    }   
]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am not even going to bother showing what I have put in the props.conf file as it might be misleading.&lt;/P&gt;

&lt;P&gt;I am facing this problem only when I am polling the JSON via REST API. In comparison, if I get the same JSON (flat file) and manually import it, Splunk is smart enough to break it down cleanly in individual events.&lt;/P&gt;

&lt;P&gt;Any assistance would be highly appreciated. Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 12:48:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-a-JSON-from-REST-API/m-p/428305#M75043</guid>
      <dc:creator>claudio_palmeri</dc:creator>
      <dc:date>2018-07-06T12:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse a JSON from REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-a-JSON-from-REST-API/m-p/428306#M75044</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;This can be handled by creating a custome responsehandler i.e by editing responsehandler.py (/rest/bin/responsehandlers.py)&lt;/P&gt;

&lt;P&gt;or you can exclude null values by adding below to your search.&lt;/P&gt;

&lt;P&gt;search | where isnull(field name)&lt;/P&gt;

&lt;P&gt;Let me know if this helps.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 19:09:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-a-JSON-from-REST-API/m-p/428306#M75044</guid>
      <dc:creator>pruthvikrishnap</dc:creator>
      <dc:date>2018-07-06T19:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse a JSON from REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-a-JSON-from-REST-API/m-p/428307#M75045</link>
      <description>&lt;P&gt;Hi pruthvikrishnapolavarapu,&lt;BR /&gt;
It does help, but I wouldn't know where to start to be honest. Is this something that you can guide me through or perhaps can you recommend a Knowledge Article to follow?&lt;/P&gt;

&lt;P&gt;Should I use the responsehandler.py would I also need to modify props.conf at all? At the moment I have a combination of SEDCMD-remove_header, SEDCMD-remove_footer, LINE_BREAKER and TIME_PREFIX that are partially doing the job, but the REGEX need some fixing...&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:21:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-a-JSON-from-REST-API/m-p/428307#M75045</guid>
      <dc:creator>claudio_palmeri</dc:creator>
      <dc:date>2020-09-29T20:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse a JSON from REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-a-JSON-from-REST-API/m-p/428308#M75046</link>
      <description>&lt;P&gt;I've seen this:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://github.com/damiendallimore/SplunkModularInputsPythonFramework/blob/master/implementations/rest/bin/responsehandlers.py"&gt;https://github.com/damiendallimore/SplunkModularInputsPythonFramework/blob/master/implementations/rest/bin/responsehandlers.py&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;and this&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/233620/how-to-use-custom-response-handlers-for-monitoring-1.html"&gt;https://answers.splunk.com/answers/233620/how-to-use-custom-response-handlers-for-monitoring-1.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;but again, I wouldn't know where to start to configure them for my exact scenario...&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 22:22:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-a-JSON-from-REST-API/m-p/428308#M75046</guid>
      <dc:creator>claudio_palmeri</dc:creator>
      <dc:date>2018-07-06T22:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse a JSON from REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-a-JSON-from-REST-API/m-p/428309#M75047</link>
      <description>&lt;P&gt;Quick update, everything was resolved by using the out of the box _json sourcetype. Not sure why I was complicating my life...&lt;/P&gt;</description>
      <pubDate>Sat, 07 Jul 2018 12:02:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-a-JSON-from-REST-API/m-p/428309#M75047</guid>
      <dc:creator>claudio_palmeri</dc:creator>
      <dc:date>2018-07-07T12:02:55Z</dc:date>
    </item>
  </channel>
</rss>

