<?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 extract values from a nested _JSON? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397621#M70887</link>
    <description>&lt;P&gt;@jverheijden please do not forget to accept the answer if you are happy with it&lt;/P&gt;</description>
    <pubDate>Tue, 29 May 2018 10:04:01 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2018-05-29T10:04:01Z</dc:date>
    <item>
      <title>How to extract values from a nested _JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397617#M70883</link>
      <description>&lt;P&gt;I have the below json, I would like to be able to extract values that are in the email, name and provider fields.&lt;/P&gt;

&lt;P&gt;Currently my Splunk query is &lt;CODE&gt;sourcetype=_json | spath msg | rex field=msg mode=sed "s/\\\//g"&lt;/CODE&gt;&lt;BR /&gt;
which gets rid of all the extra slashes. &lt;/P&gt;

&lt;P&gt;When viewing the events in the list view, I can see the name, pid and msg fields with the msg field containing all of the nested JSON. How do I get it out?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"name":"master",
"pid":0,
"msg":"INPUT-USER: {
    \"_id\":\"testId\",
    \"email\":\"secret@secret.com\",
    \"name\":\"sameAsEmail\",
    \"picture\":\"beautifulPic\",
    \"user_id\":\"randomStuff\",
    \"nickname\":\"emailUserName\",
    \"identities\":[{
        \"user_id\":\"yetAnotherSecret\",
        \"provider\":\"email\",
        \"connection\":\"email\"}]
    }
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Further information: I am not an admin and do not have access to the props.conf file&lt;/P&gt;

&lt;P&gt;Thanking you in advance! &lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 05:55:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397617#M70883</guid>
      <dc:creator>jverheijden</dc:creator>
      <dc:date>2018-05-14T05:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract values from a nested _JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397618#M70884</link>
      <description>&lt;P&gt;I think the following line is going to cause you problems:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"msg": "INPUT-USER: {
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Because of the two colons and the lack of double quotes after INPUT-USER.&lt;BR /&gt;
Assuming the lack of double quotes was a mistake and the colon after INPUT-USER is needed, you could try to "extract" your msg field first with regex, build a json and use spath.&lt;/P&gt;

&lt;P&gt;For instance, the following works fine from my own lab:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval my_json = "
    {\"name\":\"master\",
     \"pid\":0,
     \"msg\":\"INPUT-USER\": {
         \"_id\":\"testId\",
         \"email\":\"secret@secret.com\",
         \"name\":\"sameAsEmail\",
         \"picture\":\"beautifulPic\",
         \"user_id\":\"randomStuff\",
         \"nickname\":\"emailUserName\",
         \"identities\":[{
             \"user_id\":\"yetAnotherSecret\",
             \"provider\":\"email\",
             \"connection\":\"email\"}]
         }
     }
"
| rex field=my_json "(?msi)\"msg\":\s*(?&amp;lt;inputuser&amp;gt;.+)$"
| eval inputuser = "{" . inputuser
| spath input=inputuser
| rename INPUT-USER.* AS *
| table email, name, "identities{}.provider"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&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/4956i7F411C6158D4AD56/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Hope that helps,&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 07:37:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397618#M70884</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2018-05-14T07:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract values from a nested _JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397619#M70885</link>
      <description>&lt;P&gt;Thank you very much for your answer javiergn. The closing double quote after INPUT-USER was indeed missing, thanks for pointing that out! &lt;BR /&gt;
I would like to utilise the rest of the answer you have given but unsure where to put it. Where do I place the code you have included? (Pasting it into a new search returns eval (malformed) error). Your assistance is greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 02:45:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397619#M70885</guid>
      <dc:creator>jverheijden</dc:creator>
      <dc:date>2018-05-15T02:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract values from a nested _JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397620#M70886</link>
      <description>&lt;P&gt;Hi, sorry for the late reply.&lt;BR /&gt;
Based on your initial question and the format you indicated there, I would assume this is what you are looking for:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=_json
| rex field=msg "(?msi)\"msg\":\s*(?&amp;lt;inputuser&amp;gt;.+)$"
| eval inputuser = "{" . inputuser
| spath input=inputuser
| rename INPUT-USER.* AS *
| table email, name, "identities{}.provider"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If not please provide some details about the errors you are seeing.&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 13:44:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397620#M70886</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2018-05-17T13:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract values from a nested _JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397621#M70887</link>
      <description>&lt;P&gt;@jverheijden please do not forget to accept the answer if you are happy with it&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 10:04:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397621#M70887</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2018-05-29T10:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract values from a nested _JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397622#M70888</link>
      <description>&lt;P&gt;Thanks very much for your feedback. Unfortunately, I have not been able to test the search that you submitted, some major changes were requested regarding our logging etc. Once the changes are filtered through to production, I hope to spend some time on this request. I will not forget your suggestion or your help!&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 02:01:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397622#M70888</guid>
      <dc:creator>jverheijden</dc:creator>
      <dc:date>2018-05-30T02:01:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract values from a nested _JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397623#M70889</link>
      <description>&lt;P&gt;Hi @jverheijden, did the answer above help? If so, please don't forget to mark it as answered. If not please provide some feedback.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 18:36:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-values-from-a-nested-JSON/m-p/397623#M70889</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2018-08-07T18:36:53Z</dc:date>
    </item>
  </channel>
</rss>

