<?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 do I use a regular expression to extract all 22 entries of a Message field in a multiline JSON data? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281858#M85060</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;You could do a bit of config here to probably get you where you want to be. I had a go with your sample data.&lt;/P&gt;

&lt;P&gt;Assuming that your data is being written to a file, in my example,  inputs.conf looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[monitor:///path-to-folder-where-file-is]
crcSalt = &amp;lt;SOURCE&amp;gt;
host =
index = json-test
sourcetype = not-json
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If your is coming in via a different input, it shouldn't be a problem. In the example above I'm just setting the sourcetype to 'not-son', so that in props.conf I can do:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[not-json]
TRUNCATE = 0
SHOULD_LINEMERGE = false
LINE_BREAKER = (},)
MAX_EVENTS = 100000
TIME_PREFIX = "TimeStamp":
TIME_FORMAT = %Y-%m-%dT%H:%M:%S
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This means that the different SequenceNumber blocks will appear as individual events, with the timestamp from that block:&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/2444i76FC4AB836DD706E/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;You could then add some of the extractions to your props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EXTRACT-seqnumber = "SequenceNumber": (?&amp;lt;seqnumber&amp;gt;[^,]+),
EXTRACT-action = "Action": (?&amp;lt;action&amp;gt;[^,]+),
EXTRACT-context = "Context": (?&amp;lt;context&amp;gt;[^,]+),
EXTRACT-messages = "Messages": \[[\n\r]+(?&amp;lt;messages&amp;gt;[^]]+)\],
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which would then allow you to do searches like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=json-test 
| table _time seqnumber action context messages
| makemv delim="," messages
| sort +seqnumber
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Giving you a table such as:&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/2445iFEB3130234399E15/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;I'm not 100% if that exactly what you're looking for. But it might get you closer, or just give you a few other things to try.&lt;/P&gt;

&lt;P&gt;Oh, and if you want to strip the quotes from the values in the fields later, you could use something like &lt;CODE&gt;rex&lt;/CODE&gt; in sed mode:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex mode=sed field=context "s/\"([^\"]*)\"/\1/g"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 08 Feb 2017 16:23:58 GMT</pubDate>
    <dc:creator>gvmorley</dc:creator>
    <dc:date>2017-02-08T16:23:58Z</dc:date>
    <item>
      <title>How do I use a regular expression to extract all 22 entries of a Message field in a multiline JSON data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281852#M85054</link>
      <description>&lt;P&gt;How do I use a regular expression to extract all 22 entries of Message field with &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;left boundry = "Messages": [
right boundry = ],
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Especially I need following extracted for some of the message fields... &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;"Transportation Expenses: Collision or Comprehensive coverage is required for vehicle 1.",&lt;BR /&gt;
"Transportation Expenses: Collision or Comprehensive coverage is required for vehicle 2."&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Message:{
  "Activity History": [
    {
      "SequenceNumber": 1,
      "Action": "Agent Id &amp;gt; asdf",
      "Context": "Home",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:30:07"
    },
    {
      "SequenceNumber": 2,
      "Action": "Initiate_Issuance &amp;gt; xasdf",
      "Context": "Home",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:30:07"
    },
    {
      "SequenceNumber": 3,
      "Action": "Create Easy Quote",
      "Context": "Create Quote",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:30:51"
    },
    {
      "SequenceNumber": 4,
      "Action": "Adding a driver from prefill",
      "Context": "Create Quote&amp;gt;Prefill",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:31:31"
    },
    {
      "SequenceNumber": 5,
      "Action": "Adding a driver from prefill",
      "Context": "Create Quote&amp;gt;Prefill",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:31:31"
    },
    {
      "SequenceNumber": 6,
      "Action": "Adding a vehicle from prefill",
      "Context": "Contact",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:31:34"
    },
    {
      "SequenceNumber": 7,
      "Action": "Adding a vehicle from prefill",
      "Context": "Contact",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:31:34"
    },
    {
      "SequenceNumber": 8,
      "Action": "residence-info",
      "Context": "Contact",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:32:02"
    },
    {
      "SequenceNumber": 9,
      "Action": "Validate Vehicle Information",
      "Context": "Vehicles",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:33:25"
    },
    {
      "SequenceNumber": 10,
      "Action": "Save for VIN",
      "Context": "",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:33:25"
    },
    {
      "SequenceNumber": 11,
      "Action": "Validate Driver Information",
      "Context": "Drivers",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:35:02"
    },
    {
      "SequenceNumber": 12,
      "Action": "Order CR",
      "Context": "Reports",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:35:03"
    },
    {
      "SequenceNumber": 13,
      "Action": "crossindices",
      "Context": "Reports",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:35:05"
    },
    {
      "SequenceNumber": 14,
      "Action": "crossindices",
      "Context": "Reports",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:35:05"
    },
    {
      "SequenceNumber": 15,
      "Action": "Order LIS",
      "Context": "Reports",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:35:09"
    },
    {
      "SequenceNumber": 16,
      "Action": "Fetch CR",
      "Context": "Reports",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:35:14"
    },
    {
      "SequenceNumber": 17,
      "Action": "rates",
      "Context": "Reports",
      "Messages": [
        "Transportation Expenses: Collision or Comprehensive coverage is required for vehicle 1.",
        "Transportation Expenses: Collision or Comprehensive coverage is required for vehicle 2."
      ],
      "TimeStamp": "2017-02-07T13:35:48"
    },
    {
      "SequenceNumber": 18,
      "Action": "package-rates",
      "Context": "Reports",
      "Messages": [
        "Transportation Expenses: Collision or Comprehensive coverage is required for vehicle 1.",
        "Transportation Expenses: Collision or Comprehensive coverage is required for vehicle 2."
      ],
      "TimeStamp": "2017-02-07T13:35:49"
    },
    {
      "SequenceNumber": 19,
      "Action": "Update Premium &amp;gt; rates",
      "Context": "Coverages",
      "Messages": [
        "Transportation Expenses: Collision or Comprehensive coverage is required for vehicle 1.",
        "Transportation Expenses: Collision or Comprehensive coverage is required for vehicle 2."
      ],
      "TimeStamp": "2017-02-07T13:37:18"
    },
    {
      "SequenceNumber": 20,
      "Action": "Policy Package &amp;gt; package-rates",
      "Context": "Coverages",
      "Messages": [
        "Transportation Expenses: Collision or Comprehensive coverage is required for vehicle 1.",
        "Transportation Expenses: Collision or Comprehensive coverage is required for vehicle 2."
      ],
      "TimeStamp": "2017-02-07T13:37:29"
    },
    {
      "SequenceNumber": 21,
      "Action": "Print Documents",
      "Context": "Coverages",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:38:04"
    },
    {
      "SequenceNumber": 22,
      "Action": "Save Popup&amp;gt;Save &amp;amp; Exit",
      "Context": "Coverages",
      "Messages": [],
      "TimeStamp": "2017-02-07T13:38:29"
    }
  ]
} 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Feb 2017 22:37:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281852#M85054</guid>
      <dc:creator>ash2l</dc:creator>
      <dc:date>2017-02-07T22:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a regular expression to extract all 22 entries of a Message field in a multiline JSON data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281853#M85055</link>
      <description>&lt;P&gt;Is your raw data in Splunk a true json or json data embedded in regular text data?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 22:42:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281853#M85055</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-02-07T22:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a regular expression to extract all 22 entries of a Message field in a multiline JSON data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281854#M85056</link>
      <description>&lt;P&gt;Sorry, it's not a true json, Its actually the json data embedded in regular text data. We tried using following but it does not provide all the values... &lt;/P&gt;

&lt;P&gt;| rex max_match=100 "(?{[^}]+})" | mvexpand activity_history | spath input=activity_history &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:45:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281854#M85056</guid>
      <dc:creator>ash2l</dc:creator>
      <dc:date>2020-09-29T12:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a regular expression to extract all 22 entries of a Message field in a multiline JSON data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281855#M85057</link>
      <description>&lt;P&gt;Because it is JSON, just do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [your_sourcetype]
 INDEXED_EXTRACTIONS = json
 KV_MODE = none
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Feb 2017 01:10:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281855#M85057</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-02-08T01:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a regular expression to extract all 22 entries of a Message field in a multiline JSON data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281856#M85058</link>
      <description>&lt;P&gt;Oh sorry, I just edited above comment.  it's not a true json, Its actually the json data embedded in regular text data. We tried using following but it does not provide all the values...&lt;/P&gt;

&lt;P&gt;...... | rex max_match=100 "(?{[^}]+})" | mvexpand activity_history | spath input=activity_history &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:45:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281856#M85058</guid>
      <dc:creator>ash2l</dc:creator>
      <dc:date>2020-09-29T12:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a regular expression to extract all 22 entries of a Message field in a multiline JSON data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281857#M85059</link>
      <description>&lt;P&gt;If you have ONLY the JSON string, it should work from what it looks like, but the fact that it is embedded in the regular text, it can't parse it like JSON. Remove the "Message:" from the front of the event and it could be parsed properly as JSON.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 16:12:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281857#M85059</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-02-08T16:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a regular expression to extract all 22 entries of a Message field in a multiline JSON data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281858#M85060</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;You could do a bit of config here to probably get you where you want to be. I had a go with your sample data.&lt;/P&gt;

&lt;P&gt;Assuming that your data is being written to a file, in my example,  inputs.conf looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[monitor:///path-to-folder-where-file-is]
crcSalt = &amp;lt;SOURCE&amp;gt;
host =
index = json-test
sourcetype = not-json
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If your is coming in via a different input, it shouldn't be a problem. In the example above I'm just setting the sourcetype to 'not-son', so that in props.conf I can do:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[not-json]
TRUNCATE = 0
SHOULD_LINEMERGE = false
LINE_BREAKER = (},)
MAX_EVENTS = 100000
TIME_PREFIX = "TimeStamp":
TIME_FORMAT = %Y-%m-%dT%H:%M:%S
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This means that the different SequenceNumber blocks will appear as individual events, with the timestamp from that block:&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/2444i76FC4AB836DD706E/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;You could then add some of the extractions to your props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EXTRACT-seqnumber = "SequenceNumber": (?&amp;lt;seqnumber&amp;gt;[^,]+),
EXTRACT-action = "Action": (?&amp;lt;action&amp;gt;[^,]+),
EXTRACT-context = "Context": (?&amp;lt;context&amp;gt;[^,]+),
EXTRACT-messages = "Messages": \[[\n\r]+(?&amp;lt;messages&amp;gt;[^]]+)\],
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which would then allow you to do searches like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=json-test 
| table _time seqnumber action context messages
| makemv delim="," messages
| sort +seqnumber
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Giving you a table such as:&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/2445iFEB3130234399E15/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;I'm not 100% if that exactly what you're looking for. But it might get you closer, or just give you a few other things to try.&lt;/P&gt;

&lt;P&gt;Oh, and if you want to strip the quotes from the values in the fields later, you could use something like &lt;CODE&gt;rex&lt;/CODE&gt; in sed mode:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex mode=sed field=context "s/\"([^\"]*)\"/\1/g"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Feb 2017 16:23:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-a-regular-expression-to-extract-all-22-entries-of-a/m-p/281858#M85060</guid>
      <dc:creator>gvmorley</dc:creator>
      <dc:date>2017-02-08T16:23:58Z</dc:date>
    </item>
  </channel>
</rss>

