# Extraction of Fields from an Array and Creation of Columns While Maintaining the Structure, Replacing Missing Fields with Nul

**URL:** <https://community.dynatrace.com/t/extraction-of-fields-from-an-array-and-creation-of-columns-while-maintaining-the-structure-replacing-missing-fields-with-nul/50116>\
**Category:** DQL\
**Tags:** dql\
**Created:** [February 5, 2025, 7:09pm UTC](https://community.dynatrace.com/t/extraction-of-fields-from-an-array-and-creation-of-columns-while-maintaining-the-structure-replacing-missing-fields-with-nul/50116 "2025-02-05T19:09:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlos\_carreno](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/carlos_carreno/32/28820_2.png) [@carlos\_carreno](https://community.dynatrace.com/u/carlos_carreno)\
**Post date:** [February 5, 2025, 7:09pm UTC](https://community.dynatrace.com/t/extraction-of-fields-from-an-array-and-creation-of-columns-while-maintaining-the-structure-replacing-missing-fields-with-nul/50116/1 "2025-02-05T19:09:04Z")

</div>

Good afternoon, I need your help. The objective is the following process with different arrays from Bizevent:

1. Verify in each position if the field exists  
2. If it exists, create the column with the information from that position  
3. If it doesn’t exist, create the column but assign it “null”

I’ve tried it this way:

data record(a = array(“estado:bueno”,“aplica:si”,“salud:buena”,“animal:perro”)),  
record(a=array(“estado:bueno”,“aplica:si”,“salud:buena”,“animal:perro”,“lugar:francia”)),  
record(a=array(“estado:bueno”,“aplica:si”))  
| fieldsAdd if(iAny(a[] == “animal:perro”),“kk”)

I have tried to interact with the if statement so that if the condition is met, it takes the value from the position and creates the column. It would be something like this:

 ![carlos_carreno_0-1738782368859.png](https://global.discourse-cdn.com/dynatrace/original/3X/b/a/ba42f28a18c94e2b8046242d3a28904dea8f37b6.png)

---

<div class="post-metadata">

**Author:** ![krzysztof\_hoja](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/krzysztof_hoja/32/34625_2.png) [@krzysztof\_hoja](https://community.dynatrace.com/u/krzysztof_hoja)\
**Post date:** [February 13, 2025, 8:14am UTC](https://community.dynatrace.com/t/extraction-of-fields-from-an-array-and-creation-of-columns-while-maintaining-the-structure-replacing-missing-fields-with-nul/50116/2 "2025-02-13T08:14:33Z")

</div>

It looks like you are looking for “transpose” function which is not available. Currently the only way to achieve it is via workaround using DPL parsing.

To achieve view like your screenshot:

```markup
data record(a = array("estado:bueno","aplica:si","salud:buena","animal:perro")),
record(a=array("estado:bueno","aplica:si","salud:buena","animal:perro","lugar:francia")),
record(a=array("estado:bueno","aplica:si"))
| fieldsAdd a = toString(a)
| parse a, "'[' KVP{ '\"' LD:key ':' LD:value '\"' ', '? }:a ']'"
| fieldsFlatten a 
| fieldsKeep "a.*"

```

Result look like:

 ![krzysztof_hoja_0-1739434341374.png](https://global.discourse-cdn.com/dynatrace/original/3X/6/e/6ece5a84a963704a52419778a5de9414ff1347a8.png)

---

<div class="post-metadata">

**Author:** ![carlos\_carreno](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/carlos_carreno/32/28820_2.png) [@carlos\_carreno](https://community.dynatrace.com/u/carlos_carreno)\
**Post date:** [February 13, 2025, 10:39am UTC](https://community.dynatrace.com/t/extraction-of-fields-from-an-array-and-creation-of-columns-while-maintaining-the-structure-replacing-missing-fields-with-nul/50116/3 "2025-02-13T10:39:08Z")

</div>

What recommendation would you give when, in the field, I find that there is a data object that does not meet the key-value structure?

```markup
["Radicado: 13-02-20250213004567 ", 
 "Expediente Cliente: 9876543210 ", 
 "Johnathan Smith ", 
 "Zona Motor: NA ", 
 "Zona: Zona New York ", 
 "Agencia que radicó: Manhattan ", 
 "Usuario que radicó: jdoe ", 
 "Agencia origen cliente: Manhattan ", 
 "Asesor cliente: jdoe ", 
 "Radicado Visual: 1456789 ", 
 "Modalidad de crédito: Personal ", 
 "Línea de crédito: 410 - Personal Loan/International Clients ", 
 "Monto: $75,000.00 "]

```

As can be seen in the name, it does not meet the key-value condition.

thanks

---

<div class="post-metadata">

**Author:** ![krzysztof\_hoja](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/krzysztof_hoja/32/34625_2.png) [@krzysztof\_hoja](https://community.dynatrace.com/u/krzysztof_hoja)\
**Post date:** [February 13, 2025, 10:50am UTC](https://community.dynatrace.com/t/extraction-of-fields-from-an-array-and-creation-of-columns-while-maintaining-the-structure-replacing-missing-fields-with-nul/50116/4 "2025-02-13T10:50:37Z")

</div>

Do you have in mind

```markup
"Johnathan Smith ",

```

element?

How many such cases can you have in array?

How do you distinguish them from each other? Index?

And what would you like to see as a filed name / header in the table in such case?

---

<div class="post-metadata">

**Author:** ![carlos\_carreno](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/carlos_carreno/32/28820_2.png) [@carlos\_carreno](https://community.dynatrace.com/u/carlos_carreno)\
**Post date:** [February 13, 2025, 11:24am UTC](https://community.dynatrace.com/t/extraction-of-fields-from-an-array-and-creation-of-columns-while-maintaining-the-structure-replacing-missing-fields-with-nul/50116/5 "2025-02-13T11:24:44Z")

</div>

How many of those cases can you have in the array?  
Analyzing the data, they all come in that form.

How do you distinguish them from each other? Index?  
I know they are names because I know the data, but the key should be the name.

And what would you like to see as a field name/header in the table in such case?  
Name.

thanks

---

<div class="post-metadata">

**Author:** ![krzysztof\_hoja](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/krzysztof_hoja/32/34625_2.png) [@krzysztof\_hoja](https://community.dynatrace.com/u/krzysztof_hoja)\
**Post date:** [February 13, 2025, 11:34am UTC](https://community.dynatrace.com/t/extraction-of-fields-from-an-array-and-creation-of-columns-while-maintaining-the-structure-replacing-missing-fields-with-nul/50116/6 "2025-02-13T11:34:41Z")

</div>

What I had in mind was adjusting original content to format conforming with KVP.

Like in this example I append "Name: " in case ‘:’ is missing

```markup
data json:"""[{"a": ["Radicado: 13-02-20250213004567 ", 
 "Expediente Cliente: 9876543210 ", 
 "Johnathan Smith ", 
 "Zona Motor: NA ", 
 "Zona: Zona New York ", 
 "Agencia que radicó: Manhattan ", 
 "Usuario que radicó: jdoe ", 
 "Agencia origen cliente: Manhattan ", 
 "Asesor cliente: jdoe ", 
 "Radicado Visual: 1456789 ", 
 "Modalidad de crédito: Personal ", 
 "Línea de crédito: 410 - Personal Loan/International Clients ", 
 "Monto: $75,000.00 "]
 }]"""
| fieldsAdd a = if(contains(a[],":"), a[], else: concat("Name: ", a[]))
| fieldsAdd a = toString(a)
| parse a, "'[' KVP{ '\"' LD:key ':' LD:value '\"' ', '? }:a ']'"
| fieldsFlatten a 
| fieldsKeep "a.*"

```

 ![krzysztof_hoja_0-1739446459484.png](https://global.discourse-cdn.com/dynatrace/original/2X/6/6e07d4a57f02ae8ace1cbc0c0d7cf84eb3ce4f72.png)

---

<div class="post-metadata">

**Author:** ![carlos\_carreno](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/carlos_carreno/32/28820_2.png) [@carlos\_carreno](https://community.dynatrace.com/u/carlos_carreno)\
**Post date:** [February 13, 2025, 11:42am UTC](https://community.dynatrace.com/t/extraction-of-fields-from-an-array-and-creation-of-columns-while-maintaining-the-structure-replacing-missing-fields-with-nul/50116/7 "2025-02-13T11:42:41Z")

</div>

Thank you very much, you made it seem easy.&nbsp;:grin:
