# Extracting key-value pairs from log string into arrays

**URL:** <https://community.dynatrace.com/t/extracting-key-value-pairs-from-log-string-into-arrays/53714>\
**Category:** DQL\
**Tags:** dql\
**Created:** [October 13, 2025, 10:51pm UTC](https://community.dynatrace.com/t/extracting-key-value-pairs-from-log-string-into-arrays/53714 "2025-10-13T22:51:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akhil-Jayendran](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/akhil-jayendran/32/153_2.png) [@Akhil-Jayendran](https://community.dynatrace.com/u/Akhil-Jayendran)\
**Post date:** [October 13, 2025, 10:51pm UTC](https://community.dynatrace.com/t/extracting-key-value-pairs-from-log-string-into-arrays/53714/1 "2025-10-13T22:51:37Z")

</div>

Hello Team,

I have a log entry in the following format:

This is test logs ~AB:4~CD:3~CD:6~EF:5~AB:3.

From this log, I’d like to extract the values of each field and store them in arrays  
for example:

AB = [4, 3], CD = [3, 6], and so on.

Has anyone tried implementing something similar or have suggestions on how to achieve this?

I tried this way but not work

```javascript
data record( content="This is test logs ~AB:4~CD:3~CD:6~EF:5~AB:3")
| fieldsAdd test=splitString(content, "~")
| fieldsAdd test=toString(test)
| parse test, "'[' KVP{ '\"' LD:key ':' LD:value '\"' ', '? }:test ']'"

```

Regards,

Akhil Jayendran

---

<div class="post-metadata">

**Author:** ![Mohamed\_Hamdy](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@Mohamed\_Hamdy](https://community.dynatrace.com/u/Mohamed_Hamdy)\
**Post date:** [October 14, 2025, 6:51am UTC](https://community.dynatrace.com/t/extracting-key-value-pairs-from-log-string-into-arrays/53714/2 "2025-10-14T06:51:23Z")

</div>

Hi&nbsp;[@Akhil-Jayendran](https://community.dynatrace.com/user/52584)&nbsp;,

I believe the below should work.

```markup
data record(content="This is test logs ~AB:4~CD:3~CD:6~EF:5~AB:3")
| fieldsAdd test = splitString(content, "~")
| expand test
| filter contains(test, ":")
| parse test, "LD:key ':' LONG:value"
| summarize values = collectArray(value), by: { key }

```

---

<div class="post-metadata">

**Author:** ![Akhil-Jayendran](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/akhil-jayendran/32/153_2.png) [@Akhil-Jayendran](https://community.dynatrace.com/u/Akhil-Jayendran)\
**Post date:** [October 14, 2025, 2:52pm UTC](https://community.dynatrace.com/t/extracting-key-value-pairs-from-log-string-into-arrays/53714/3 "2025-10-14T14:52:26Z")

</div>

Hello&nbsp;[@Mohamed\_Hamdy](https://community.dynatrace.com/user/4007)&nbsp;,

Appreciate your help, it helped me partially&nbsp;  
My end goal is to&nbsp; display the data like this , without summarize any way to get this info

| Content | AB | CD | EF | arraymax(AB) | arraymin(AB) | arraymax(CD) | arraymin(CD) |
| --- | --- | --- | --- | --- | --- | --- | --- |
| This is test logs ~AB:4~CD:3~CD:6~EF:5~AB:3 | 4,3 | 3,6 | 5 | 4 | 3 | 6 | 3 |

Regards,  
Akhil Jayendran

---

<div class="post-metadata">

**Author:** ![t\_pawlak](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/t_pawlak/32/14991_2.png) [@t\_pawlak](https://community.dynatrace.com/u/t_pawlak)\
**Post date:** [October 15, 2025, 2:05pm UTC](https://community.dynatrace.com/t/extracting-key-value-pairs-from-log-string-into-arrays/53714/4 "2025-10-15T14:05:26Z")

</div>

Try this:

```markup
data record(content = "This is test logs ~AB:4~CD:3~CD:6~EF:5~AB:3")
| fieldsAdd parts = splitString(content, "~")
| expand parts
| filter contains(parts, ":")
| parse parts, "LD:key ':' LONG:value"
| summarize
    AB = arrayRemoveNulls(collectArray(if(key == "AB", value, else: NULL))),
    CD = arrayRemoveNulls(collectArray(if(key == "CD", value, else: NULL))),
    EF = arrayRemoveNulls(collectArray(if(key == "EF", value, else: NULL))),
  by: { content }
| fieldsAdd
    `arraymax(AB)` = arrayMax(AB),
    `arraymin(AB)` = arrayMin(AB),
    `arraymax(CD)` = arrayMax(CD),
    `arraymin(CD)` = arrayMin(CD)

```

you should revice this:

![t_pawlak_0-1760537112976.png](https://global.discourse-cdn.com/dynatrace/original/3X/b/0/b083a4b8662a02e61924438e1bbe96bf69cdcf8d.png)
