<?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 can I extract the JSON data as key value pair? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344354#M63346</link>
    <description>&lt;P&gt;Give this a try  (first two lines are to generate sample data)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval _raw="{\"field1\": \"value1\", \"field2\": \"value2\", \"field3\": \"value3\", \"field4\": \"{\\\"subfield1\\\":\\\"value\\\",\\\"subfield2\\\":\\\"value\\\"}\", \"field\": \"value\"}" | table _raw 
| rex field=_raw mode=sed "s/\\\\"/"/g s/\"\{/[{/ s/\}\"/}]/"| spath
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 20 Apr 2018 16:42:26 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-04-20T16:42:26Z</dc:date>
    <item>
      <title>How can I extract the JSON data as key value pair?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344353#M63345</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have extracted the JSON data. After data indexed I found that one field contains another format of JSON data which is indexed as a string. Please help me in extracting the data. Please find the log details below which I had received from indexer after the indexing.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"field1": "value1", "field2": "value2", "field3": "value3", "field4": "{\"subfield\":\"value\",\"subfield\":\"value\"}", "field": "value"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please help me in extracting the data as key value pair which is present in the field4 . Rest fields are able to parse the data correctly.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Sam&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 15:01:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344353#M63345</guid>
      <dc:creator>soumyacharya91</dc:creator>
      <dc:date>2018-04-20T15:01:46Z</dc:date>
    </item>
    <item>
      <title>Re: How can I extract the JSON data as key value pair?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344354#M63346</link>
      <description>&lt;P&gt;Give this a try  (first two lines are to generate sample data)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval _raw="{\"field1\": \"value1\", \"field2\": \"value2\", \"field3\": \"value3\", \"field4\": \"{\\\"subfield1\\\":\\\"value\\\",\\\"subfield2\\\":\\\"value\\\"}\", \"field\": \"value\"}" | table _raw 
| rex field=_raw mode=sed "s/\\\\"/"/g s/\"\{/[{/ s/\}\"/}]/"| spath
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Apr 2018 16:42:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344354#M63346</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-04-20T16:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can I extract the JSON data as key value pair?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344355#M63347</link>
      <description>&lt;P&gt;I am not sure that I get exactly what you need but try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"field1\": \"value1\", \"field2\": \"value2\", \"field3\": \"value3\", \"field4\": \"{\\\"subfield\\\":\\\"value1\\\",\\\"subfield\\\":\\\"value2\\\"}\", \"field\": \"value\"}"

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| spath field4
| rex field=field4 max_match=0 "\"subfield\":\s*\"(?&amp;lt;field4&amp;gt;[^\"]+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Apr 2018 20:00:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344355#M63347</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-04-22T20:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: How can I extract the JSON data as key value pair?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344356#M63348</link>
      <description>&lt;P&gt;Hi woodcock,&lt;/P&gt;

&lt;P&gt;I have tried the solution but it is not working. &lt;/P&gt;

&lt;P&gt;I tried below query along with my base search and checked it is properly extracting the data but I don't know how to apply this in splunk backend files. Is there any way we can apply this solution to props.conf / transforms.conf&lt;/P&gt;

&lt;P&gt;|spath input = field4&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Sam&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 09:05:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344356#M63348</guid>
      <dc:creator>soumyacharya91</dc:creator>
      <dc:date>2018-04-23T09:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: How can I extract the JSON data as key value pair?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344357#M63349</link>
      <description>&lt;P&gt;@soumyacharya91, can you try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   | makeresults 
       | eval _raw="{\"field1\": \"value1\", \"field2\": \"value2\", \"field3\": \"value3\", \"field4\": \"{\\\"subfield\\\":\\\"value1\\\",\\\"subfield\\\":\\\"value2\\\"}\", \"field\": \"value\"}"
       | extract 
       | rex field=field4 "\"subfield\":\s*\"(?&amp;lt;subfield1&amp;gt;[^\"]+)\",\"subfield\":\s*\"(?&amp;lt;subfield2&amp;gt;[^\"]+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Apr 2018 09:14:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344357#M63349</guid>
      <dc:creator>TISKAR</dc:creator>
      <dc:date>2018-04-23T09:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: How can I extract the JSON data as key value pair?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344358#M63350</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;It is not working.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 09:15:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344358#M63350</guid>
      <dc:creator>soumyacharya91</dc:creator>
      <dc:date>2018-04-23T09:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: How can I extract the JSON data as key value pair?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344359#M63351</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;This is not working.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 09:22:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344359#M63351</guid>
      <dc:creator>soumyacharya91</dc:creator>
      <dc:date>2018-04-23T09:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: How can I extract the JSON data as key value pair?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344360#M63352</link>
      <description>&lt;P&gt;So try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
          | eval _raw="{\"field1\": \"value1\", \"field2\": \"value2\", \"field3\": \"value3\", \"field4\": \"{\\\"subfield\\\":\\\"value1\\\",\\\"subfield\\\":\\\"value2\\\"}\", \"field\": \"value\"}"
          | extract 
          | rex field=field4 "\"subfield\":\s*\"(?&amp;lt;subfield1&amp;gt;[^\"]+)\",\"subfield\":\s*\"(?&amp;lt;subfield2&amp;gt;[^\"]+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Apr 2018 09:27:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344360#M63352</guid>
      <dc:creator>TISKAR</dc:creator>
      <dc:date>2018-04-23T09:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: How can I extract the JSON data as key value pair?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344361#M63353</link>
      <description>&lt;P&gt;| rename _raw AS _temp field4 AS _raw | extract pairdelim="?&amp;amp;" kvdelim="=" | rename _raw AS field4 _temp AS _raw&lt;/P&gt;

&lt;P&gt;You can try this, it extracts all the nested key, value pairs at search time&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 16:58:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344361#M63353</guid>
      <dc:creator>vsai0718</dc:creator>
      <dc:date>2019-08-27T16:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: How can I extract the JSON data as key value pair?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344362#M63354</link>
      <description>&lt;P&gt;You can try this one &lt;BR /&gt;
 &lt;CODE&gt;| rename _raw AS _temp field4 AS _raw | extract pairdelim="?&amp;amp;" kvdelim="=" | rename _raw AS field4 _temp AS _raw&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 17:00:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344362#M63354</guid>
      <dc:creator>vsai0718</dc:creator>
      <dc:date>2019-08-27T17:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: How can I extract the JSON data as key value pair?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344363#M63355</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"field1\": \"value1\", \"field2\": \"value2\", \"field3\": \"value3\", \"field4\": \"{\\\"subfield\\\":\\\"value1\\\",\\\"subfield\\\":\\\"value2\\\"}\", \"field\": \"value\"}" 
| rename COMMENT AS "Everything above generates sample event data; everything below is your solution" 
| rex max_match=0 "\\\\\"subfield\\\\\":\s*\\\\\"(?&amp;lt;field4&amp;gt;[^\\\\\"]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This &lt;CODE&gt;RegEx&lt;/CODE&gt; string is not dependent on the &lt;CODE&gt;spath&lt;/CODE&gt; so it can be used in &lt;CODE&gt;props.conf&lt;/CODE&gt; directly.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 02:35:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344363#M63355</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-10-26T02:35:52Z</dc:date>
    </item>
    <item>
      <title>Re: How can I extract the JSON data as key value pair?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344364#M63356</link>
      <description>&lt;P&gt;See my other answer.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 02:36:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-extract-the-JSON-data-as-key-value-pair/m-p/344364#M63356</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-10-26T02:36:13Z</dc:date>
    </item>
  </channel>
</rss>

