# Parse log data that contains \\n (newline)

**URL:** <https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497>\
**Category:** DQL\
**Tags:** dql, logs\
**Created:** [July 16, 2025, 6:00am UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497 "2025-07-16T06:00:06Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![avdveen](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@avdveen](https://community.dynatrace.com/u/avdveen)\
**Post date:** [July 16, 2025, 6:00am UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/1 "2025-07-16T06:00:06Z")

</div>

Hi,

I’ve been struggling with the DQL processor definition syntax and just not winning…any suggestions on how to parse the items and their respective values for all the ‘Order’ items in the “message” part of this log?

```auto
{
"thread": "redacted::redacted",
"level": "INFO",
"loggerName": "de.hybris.redacted",
"time": "2025-07-16 05:45:14.751",
"endOfBatch": "false",
"message ": "OrderCountSentToday: 378\nOrderCountSentLast10Minutes: 66\nOrderCountErroredToday: 0\nOrderCountErroredLast10Minutes: 0\nOrderCountNonCancelledToday: 378\nOrderCountVsSent: 0\nAverageOrderSendTimeToday: 8.634920634920634\nAverageOrderSendTimeLast10Minutes: 7.848484848484849\nAverageOrderTimeWaitingToSend: 0.0\nTaskCount: 23\n",
"mdc": {
"CronJob": "(jobname) ",
"Tenant": ""
}
}

```

Also, what would the matching condition be, because anything I’ve tried other than ‘true’ doesn’t work either.

---

<div class="post-metadata">

**Author:** ![GerardJ](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gerardj/32/154_2.png) [@GerardJ](https://community.dynatrace.com/u/GerardJ)\
**Post date:** [July 16, 2025, 8:35am UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/2 "2025-07-16T08:35:53Z")

</div>

Hi&nbsp;[@andre\_vdveen](https://community.dynatrace.com/user/11931)&nbsp;  
In such case, I would use DPL with KVP, like this :  
| parse content, “”“DATA “message \”: \”" LD:message “\”“”“”  
| parse message, “”“KVP{ALNUM:key ‘:’ LD:value ‘\\n’}:attr”“”

For matching condition, it really depends how this log is collected and if you can rely on “log.source” or other added attributes

---

<div class="post-metadata">

**Author:** ![avdveen](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@avdveen](https://community.dynatrace.com/u/avdveen)\
**Post date:** [July 16, 2025, 9:24am UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/3 "2025-07-16T09:24:51Z")

</div>

Hi&nbsp;[@GerardJ](https://community.dynatrace.com/user/66575)&nbsp;  
Thank you for the suggestion; I tested it but it doesn’t parse the content of what’s contained in "message " into key:value pairs as I expected.

Did it work for you when you tested it?

---

<div class="post-metadata">

**Author:** ![GerardJ](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gerardj/32/154_2.png) [@GerardJ](https://community.dynatrace.com/u/GerardJ)\
**Post date:** [July 16, 2025, 12:12pm UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/4 "2025-07-16T12:12:22Z")

</div>

it seemed to work, I got this result (raw reponse):

 ![GerardJ_0-1752667860383.png](https://global.discourse-cdn.com/dynatrace/original/3X/c/2/c2f8bdd91bb3f4a3250f676a046f518f4a5d1404.png)

---

<div class="post-metadata">

**Author:** ![avdveen](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@avdveen](https://community.dynatrace.com/u/avdveen)\
**Post date:** [July 16, 2025, 12:27pm UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/5 "2025-07-16T12:27:06Z")

</div>

Thanks for sharing the result - is that in a Notebook?  
I tried it in OpenPipeline, doesn’t seem to work there.

 ![andre_vdveen_1-1752669090780.png](https://global.discourse-cdn.com/dynatrace/original/3X/4/7/47e947b0aad4908f2fb351dd1821e7f44b2bcae8.png)

---

<div class="post-metadata">

**Author:** ![GerardJ](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gerardj/32/154_2.png) [@GerardJ](https://community.dynatrace.com/u/GerardJ)\
**Post date:** [July 16, 2025, 1:09pm UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/6 "2025-07-16T13:09:00Z")

</div>

Yes I did it in a notebook and&nbsp;i took the whole log payload as content, so the behavior is not the same, I also probably made a bad copy/paste because the JSON parsing didn’t work…  
To do it in a pipeline, i had to use a workaround with an extra field because of a space at the end of the message field name

 ![GerardJ_0-1752671222575.png](https://global.discourse-cdn.com/dynatrace/original/3X/7/2/72b1dd4b442d6ce381879119f21ef3d486ca7232.png)

---

<div class="post-metadata">

**Author:** ![avdveen](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@avdveen](https://community.dynatrace.com/u/avdveen)\
**Post date:** [July 16, 2025, 2:39pm UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/7 "2025-07-16T14:39:55Z")

</div>

Ah thank you so much,&nbsp;[@GerardJ](https://community.dynatrace.com/user/66575), that works! 😄  
Here’s my complete processor definition, hopefully it helps someone else in future too.

```auto
fieldsAdd message2=`message `<br>| parse message2, """KVP{ALNUM:key ':' LD:value EOL}:attr"""<br>| fieldsFlatten attr

```

---

<div class="post-metadata">

**Author:** ![avdveen](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@avdveen](https://community.dynatrace.com/u/avdveen)\
**Post date:** [July 21, 2025, 8:41pm UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/8 "2025-07-21T20:41:51Z")

</div>

Either I’m just too dumb to understand the DQL syntax, or there is a discrepancy in how the pipeline processes the log data.

When I use the DQL provided, both ‘message2’ and ‘attr’ fields contains nothing when I check it in a Notebook.

 ![andre_vdveen_1-1753130451450.png](https://global.discourse-cdn.com/dynatrace/original/2X/8/87344a222133fead06f72011e6c3dea693eb63ae.png)

I assume that’s the reason my value metric extraction rules in the pipeline doesn’t work either, even though the preview in the pipeline shows the ‘message2’ and ‘attr’ fields containing the data I’m looking for and flattening ‘attr’ returns the fields and their value that I’m after.  
**ID:&nbsp;pipeline\__redacted_\_8335**

 ![andre_vdveen_0-1753130320623.png](https://global.discourse-cdn.com/dynatrace/original/2X/0/0e049aa89b69c165deb58253da5e5bede136ef62.png)

---

<div class="post-metadata">

**Author:** ![GerardJ](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gerardj/32/154_2.png) [@GerardJ](https://community.dynatrace.com/u/GerardJ)\
**Post date:** [July 22, 2025, 7:42am UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/9 "2025-07-22T07:42:50Z")

</div>

it wouldn’t be the first time that there’s been a difference between the “run sample data” and what’s actually available at the end of the processing, but for me it’s quite rare.  
Just to make sure I understand, are the attr.\* fields that result from fieldsFlatten also absent or null?  
Have you tried testing the same processing as the pipeline in a notebook on these logs to see if it works?

---

<div class="post-metadata">

**Author:** ![avdveen](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@avdveen](https://community.dynatrace.com/u/avdveen)\
**Post date:** [July 22, 2025, 8:15am UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/10 "2025-07-22T08:15:52Z")

</div>

I did try, but it doesn’t seem to do the same in Notebooks as in the pipeline; I guess the attr.\* fields are not showing up because it doesn’t contain anything in attr?

 ![andre_vdveen_0-1753172044704.png](https://global.discourse-cdn.com/dynatrace/original/3X/a/e/ae19ed591e166da0f9204172b23748a48d791ff9.png)

---

<div class="post-metadata">

**Author:** ![GerardJ](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gerardj/32/154_2.png) [@GerardJ](https://community.dynatrace.com/u/GerardJ)\
**Post date:** [July 22, 2025, 9:13am UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/11 "2025-07-22T09:13:09Z")

</div>

Yes you’re right for the attr.\* not showing up if attr is null.  
Did you check if in the log content if the message field still have the same name with a space at the end ?

---

<div class="post-metadata">

**Author:** ![avdveen](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@avdveen](https://community.dynatrace.com/u/avdveen)\
**Post date:** [July 22, 2025, 12:05pm UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/12 "2025-07-22T12:05:20Z")

</div>

Just sanity checking, thanks for confirming I’m not losing my marbles completely, haha! 😉  
Yes, the space behind "message " is still there in the actual logs.

What would be the best option to get to the bottom of this: open a chat or support ticket? It’s getting a little urgent, the client is looking for the values in log metrics and I’ve been struggling this for too long now 😞

---

<div class="post-metadata">

**Author:** ![GerardJ](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gerardj/32/154_2.png) [@GerardJ](https://community.dynatrace.com/u/GerardJ)\
**Post date:** [July 22, 2025, 12:45pm UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/13 "2025-07-22T12:45:14Z")

</div>

From your example in the notebook, I think the log record is different from what is used as a sample in the pipeline. In the notebook, `message :` is inside the content field but in the pipeline we parse it as a field of the log record.  
So you probably need to add these two steps to extract the message :

```markup
| parse content, """JSON:parse"""
| fields message2=parse[`message `]

```

before parsing message2  
Also use the raw response view in the notebook to copy/paste a complete log record to add it as sample in the open pipeline.

---

<div class="post-metadata">

**Author:** ![avdveen](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@avdveen](https://community.dynatrace.com/u/avdveen)\
**Post date:** [July 23, 2025, 2:41pm UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/14 "2025-07-23T14:41:24Z")

</div>

Your help is very much appreciated, [@GerardJ](https://community.dynatrace.com/user/66575)! I would be dead in the water without it. :thankyou:

I finally managed to get it to work e.g., create the metrics - the DQL you gave helped but I had to make one small change to it, which ended up giving me the result I wanted: metrics!

The change I made, based on a colleagues observation and suggestion, was to use _fieldsAdd_ and not just _fields_ when creating the field _message2_. I also removed the _| fields message2_ line as that also seemingly interfered with the metric creation.

Here’s the final DQL processor definition:

```auto
parse content, """JSON:parse"""
| fieldsAdd message2=parse[`message `]
| parse message2, """KVP{ALNUM:key ': ' FLOAT:value EOL}:attr"""
| fieldsAdd attr
| fieldsFlatten attr

```

---

<div class="post-metadata">

**Author:** ![GerardJ](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gerardj/32/154_2.png) [@GerardJ](https://community.dynatrace.com/u/GerardJ)\
**Post date:** [July 24, 2025, 6:36am UTC](https://community.dynatrace.com/t/parse-log-data-that-contains-n-newline/52497/15 "2025-07-24T06:36:08Z")

</div>

Glad it works ! And you’re absolutely right, an arbitrary and bizarre choice on my part to use the _fields_ command&nbsp;🤔&nbsp;especially since I never use it in pipelines&nbsp;😅  
It’s better to use _fieldsAdd_ in a pipeline processing as it&nbsp;allows you to add additional fields while preserving existing ones, which is important for maintaining log context or using these fields as metric dimensions.  
You could also remove the extracted fields _parse_ and _message2_ as after parsing you probably won’t need them anymore :

```markup
| fieldsRemove parse, message2

```
