<?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 DQL parsing on a log line that has free text and nested JSON in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/DQL-parsing-on-a-log-line-that-has-free-text-and-nested-JSON/m-p/216945#M114</link>
    <description>&lt;DIV class="p-rich_text_section"&gt;Hi team, I'm trying to extract certain fields&lt;CODE class="c-mrkdwn__code" data-stringify-type="code"&gt;(acctAccountNumber,payerAddr and value)&lt;/CODE&gt;from a log line that has a mix of free text followed by a nested JSON - tried different variants but I'm still getting it wrong, any insights please on how to parse this correctly?&lt;/DIV&gt;
&lt;PRE class="c-mrkdwn__pre" data-stringify-type="pre"&gt;fetch logs
| filter matchesPhrase(content, "sendmoneysave")
| parse content, "JSON:contentjson"
| parse contentjson[data], "JSON:data",data[payer], "JSON:payer", payer[acctType], "JSON:acctType", data[amountVO], "JSON:amountVO"
//| parse contentjson[data][payer], "JSON:payer", contentjson[data][acctType],"JSON:acctType", contentjson[data][amountVO],"JSON:amountVO"
| fields timestamp, content, contentjson[data][payer][acctType][acctAccountNumber], contentjson[data][payer][payerAddr],contentjson[data][amountVO][value]&lt;/PRE&gt;
&lt;DIV class="p-rich_text_section"&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;2023-07-05T10:51:42.203+05:30 trace_id=bc94d547c317e981f8a357c7e95ca296  INFO 1 --- [erContainer-C-1] c.f.u.c.util.ReceiveMessageService       : dt.trace_sampled: true, dt.trace_id: b034e72f14a388f463707da83fdb2689, dt.entity.host_group: HOST_GROUP-C6DE8A2EA15DFABA, dt.entity.process_group_instance: PROCESS_GROUP_INSTANCE-500094DBC5C058BC, dt.span_id: 4784dfcfa6ba0185, dt.entity.host: HOST-33FE70BF62D9375A message received: | topicVsMsgtotxn:
{
	"id":"bc94d547c317e981f8a357c7e95ca296",
	"type":"sendMoneySave",
	"data":"
		{
			\"payer\":
				{
					\"acctType\":
						{
							\"acctAccountIfsc\":\"123ABC\",
							\"acctAccountNumber\":\"123456\",
							\"acctAccountType\":\"SAVINGS\",
							\"acctAccountAddrType\":\"ACCOUNT\"
					},
					\"credVO\":null,
					\"amountVO\":null,
					\"respRefVO\":null,
					\"payerAddr\":\"917907162853@okidf\",
					\"payerCode\":\"0000\",
					\"upiAccountId\":null,
					\"consumerId\":null,
					\"consentValue\":null
				},
			\"amountVO\":
				{
					\"currency\":\"INR\",
					\"value\":200.0
				},
			\"signature\":null,
		}
	","data_base64":null
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;</description>
    <pubDate>Wed, 05 Jul 2023 11:16:08 GMT</pubDate>
    <dc:creator>shrilekha-s</dc:creator>
    <dc:date>2023-07-05T11:16:08Z</dc:date>
    <item>
      <title>DQL parsing on a log line that has free text and nested JSON</title>
      <link>https://community.dynatrace.com/t5/DQL/DQL-parsing-on-a-log-line-that-has-free-text-and-nested-JSON/m-p/216945#M114</link>
      <description>&lt;DIV class="p-rich_text_section"&gt;Hi team, I'm trying to extract certain fields&lt;CODE class="c-mrkdwn__code" data-stringify-type="code"&gt;(acctAccountNumber,payerAddr and value)&lt;/CODE&gt;from a log line that has a mix of free text followed by a nested JSON - tried different variants but I'm still getting it wrong, any insights please on how to parse this correctly?&lt;/DIV&gt;
&lt;PRE class="c-mrkdwn__pre" data-stringify-type="pre"&gt;fetch logs
| filter matchesPhrase(content, "sendmoneysave")
| parse content, "JSON:contentjson"
| parse contentjson[data], "JSON:data",data[payer], "JSON:payer", payer[acctType], "JSON:acctType", data[amountVO], "JSON:amountVO"
//| parse contentjson[data][payer], "JSON:payer", contentjson[data][acctType],"JSON:acctType", contentjson[data][amountVO],"JSON:amountVO"
| fields timestamp, content, contentjson[data][payer][acctType][acctAccountNumber], contentjson[data][payer][payerAddr],contentjson[data][amountVO][value]&lt;/PRE&gt;
&lt;DIV class="p-rich_text_section"&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;2023-07-05T10:51:42.203+05:30 trace_id=bc94d547c317e981f8a357c7e95ca296  INFO 1 --- [erContainer-C-1] c.f.u.c.util.ReceiveMessageService       : dt.trace_sampled: true, dt.trace_id: b034e72f14a388f463707da83fdb2689, dt.entity.host_group: HOST_GROUP-C6DE8A2EA15DFABA, dt.entity.process_group_instance: PROCESS_GROUP_INSTANCE-500094DBC5C058BC, dt.span_id: 4784dfcfa6ba0185, dt.entity.host: HOST-33FE70BF62D9375A message received: | topicVsMsgtotxn:
{
	"id":"bc94d547c317e981f8a357c7e95ca296",
	"type":"sendMoneySave",
	"data":"
		{
			\"payer\":
				{
					\"acctType\":
						{
							\"acctAccountIfsc\":\"123ABC\",
							\"acctAccountNumber\":\"123456\",
							\"acctAccountType\":\"SAVINGS\",
							\"acctAccountAddrType\":\"ACCOUNT\"
					},
					\"credVO\":null,
					\"amountVO\":null,
					\"respRefVO\":null,
					\"payerAddr\":\"917907162853@okidf\",
					\"payerCode\":\"0000\",
					\"upiAccountId\":null,
					\"consumerId\":null,
					\"consentValue\":null
				},
			\"amountVO\":
				{
					\"currency\":\"INR\",
					\"value\":200.0
				},
			\"signature\":null,
		}
	","data_base64":null
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 05 Jul 2023 11:16:08 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/DQL-parsing-on-a-log-line-that-has-free-text-and-nested-JSON/m-p/216945#M114</guid>
      <dc:creator>shrilekha-s</dc:creator>
      <dc:date>2023-07-05T11:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: DQL parsing on a log line that has free text and nested JSON</title>
      <link>https://community.dynatrace.com/t5/DQL/DQL-parsing-on-a-log-line-that-has-free-text-and-nested-JSON/m-p/216962#M115</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/51749"&gt;@shrilekha-s&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason why your query is not working is because the inner json is not a valid json and parsing for it doesn't work. Please have a look at following screenshot&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sinisa_zubic_0-1688561205465.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/12677i258E847FA394FB5C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sinisa_zubic_0-1688561205465.png" alt="sinisa_zubic_0-1688561205465.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;for this particular case, where at the end you have a colon, line break, two tabs and a closed curly bracket I made the query work&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;fetch logs
| filter matchesPhrase(content, "sendmoneysave")
| parse content, "DATA JSON:contentjson"
| parse contentjson[data], """DATA:data ',\n		}' """
| fieldsAdd data = concat(data,"}")
| parse data, """data? json:datajson""" 
| fields acctAccountNumber=datajson[payer][acctType][acctAccountNumber]
  , payerAddress = datajson[payer][payerAddr]
  , value = datajson[amountVO][value]&lt;/LI-CODE&gt;
&lt;P&gt;and here the result, based on the sample data&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sinisa_zubic_1-1688561619122.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/12678iBF5A4F2559E35416/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sinisa_zubic_1-1688561619122.png" alt="sinisa_zubic_1-1688561619122.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;BR /&gt;Sini&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 12:53:52 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/DQL-parsing-on-a-log-line-that-has-free-text-and-nested-JSON/m-p/216962#M115</guid>
      <dc:creator>sinisa_zubic</dc:creator>
      <dc:date>2023-07-05T12:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: DQL parsing on a log line that has free text and nested JSON</title>
      <link>https://community.dynatrace.com/t5/DQL/DQL-parsing-on-a-log-line-that-has-free-text-and-nested-JSON/m-p/216967#M116</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/38283"&gt;@sinisa_zubic&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 13:48:55 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/DQL-parsing-on-a-log-line-that-has-free-text-and-nested-JSON/m-p/216967#M116</guid>
      <dc:creator>shrilekha-s</dc:creator>
      <dc:date>2023-07-05T13:48:55Z</dc:date>
    </item>
  </channel>
</rss>

