# Help! Best Practices for Handling fields in Business Event Processing

**URL:** <https://community.dynatrace.com/t/help-best-practices-for-handling-fields-in-business-event-processing/49344>\
**Category:** DQL\
**Tags:** dql, business-analytics\
**Created:** [December 12, 2024, 9:21pm UTC](https://community.dynatrace.com/t/help-best-practices-for-handling-fields-in-business-event-processing/49344 "2024-12-12T21:21:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tracegazer](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/tracegazer/32/32785_2.png) [@tracegazer](https://community.dynatrace.com/u/tracegazer)\
**Post date:** [December 12, 2024, 9:21pm UTC](https://community.dynatrace.com/t/help-best-practices-for-handling-fields-in-business-event-processing/49344/1 "2024-12-12T21:21:53Z")

</div>

Hello Community! I’m trying to create processing rules for fields corresponding to already configured business events. Specifically, I am extracting a field with the structure “[{},{},{},{},{},{},{},{},{}]”, which I can’t process to get the last array/object. In the file, you can see the structure that is obtained daily. The data is collected minute by minute, with a new object being added, ending in 319 with a daily cycle, but this doesn’t affect the result.

So far, I have implemented a rather rudimentary solution where I remove the brackets and read it as JSON. But the result is not as expected, although it’s close.

```markup
fetch bizevents
| filter event.provider == "VORTEX Nginx"
| fieldsAdd Array1=replaceString(res.body.result, "[", "")
| fieldsAdd result=replaceString(Array1, "]", "")
| parse result, "JSON:json"
| fieldsFlatten json
| fields json.time

```

 ![afuentes_0-1734037979129.png](https://global.discourse-cdn.com/dynatrace/original/3X/7/5/756bf53a0429bd312f7545f7b66588ec27956fb3.png)

**In the previous query, I get the first value from all the objects. How can I process the field to extract only the last array/object?**

 ![afuentes_1-1734038441567.png](https://global.discourse-cdn.com/dynatrace/original/3X/0/e/0e262296e85467374a4ff94b55921a9ae5e53b61.png)

I sincerely appreciate any help you can provide!  
[res.body.result.json.zip](https://community.dynatrace.com/uploads/short-url/753KQ1pphbF4Rfr7Q9YW7EqLYtU.zip) (2.42 KB)

---

<div class="post-metadata">

**Author:** ![Tiit\_Hallas](https://avatars.discourse-cdn.com/v4/letter/t/cdc98d/32.png) [@Tiit\_Hallas](https://community.dynatrace.com/u/Tiit_Hallas)\
**Post date:** [December 15, 2024, 9:32pm UTC](https://community.dynatrace.com/t/help-best-practices-for-handling-fields-in-business-event-processing/49344/2 "2024-12-15T21:32:22Z")

</div>

The object in the text file is an JSON array. There is a [JSON\_ARRAY matcher](https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-pattern-language/log-processing-json-array) for that in DPL that can be used without additional processing. If you want to extract ONLY the last element, you can use the following DQL query:

```markup
fetch bizevents
| filter event.provider == "VORTEX Nginx"
| parse content, """JSON_ARRAY:parsed_json_elements"""
| fields last_element = arrayLast(parsed_json_elements)

```

If you would like to use the JSON elements as separate fields, you can add the fieldsFlatten command to the end of the query, as follows:

```markup
fetch bizevents
| filter event.provider == "VORTEX Nginx"
| parse content, """JSON_ARRAY:parsed_json_elements"""
| fields last_element = arrayLast(parsed_json_elements)
| fieldsFlatten last_element

```

I created a demo for this in the Security Investigator at our Playgorund: [Dynatrace](https://wkf10640.apps.dynatrace.com/ui/apps/dynatrace.security.investigator/share/3262363c-d7a6-429a-b55d-a25dc5e1a9f0)

---

<div class="post-metadata">

**Author:** ![tracegazer](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/tracegazer/32/32785_2.png) [@tracegazer](https://community.dynatrace.com/u/tracegazer)\
**Post date:** [December 18, 2024, 4:17pm UTC](https://community.dynatrace.com/t/help-best-practices-for-handling-fields-in-business-event-processing/49344/3 "2024-12-18T16:17:38Z")

</div>

**Thanks to your comment** , I was able to obtain the required information. I wasn’t aware of the use of JSON\_ARRAY, but I’ve saved it for future cases.

That said, is it possible to transform the DQL query into a processing definition?

PARSE(res.body.result, “JSON\_ARRAY:jsonElement”)  
| FIELDS\_ADD(lastElement:ARRAY\_LAST(jsonElement))

 ![afuentes_0-1734538709828.png](https://global.discourse-cdn.com/dynatrace/original/3X/f/5/f51d5e5b7e00a4a8f491621d4914bba4ca865a73.png)
