23 Mar 2023 02:17 PM
I'm having trouble extracting array attributes when there isn't a top level name for the array.
For example, given the following json request body payload:
[{"Account":"f2fafaf3a","Name":"John Doe","MediumID":"a9fjah"}]
How do I extract the value for Account or Name in the Business Analytics capture rules? The documentation here doesn't seem to cover this use case.
Solved! Go to Solution.
04 Apr 2023 08:27 AM
An example of capturing a JSON with nested array (with a JSON element inside of it in position 0):
{
"id2": "json_with_array_json_nested",
"accountData":
[
{
"Account": "f2fafaf3a",
"Name": "John Doe",
"MediumID": "a9fjah"
}
]
}
Path to capture account name:
accountData.0.Account
This works to get the first position of the array "0" and the value inside the nested JSON. This works on single value arrays.
04 Apr 2023 09:05 PM
Thanks, that unfortunately doesn't cover the use case when your data sample omits accountData key for the array.
I ended up using DQL parse and was able to retrieve the correct value.
PARSE(requestbody, "DATA 'Account'LD SPACE?':' SPACE? DQS:Account ")
05 Apr 2023 05:10 PM
Ok, so the request body is an array containing a single JSON. Understood.
A processing rule works fine then. great!
02 Oct 2024 12:26 PM
Linked here from our good friend @KlausEnzenhofer - with a second question for ya: what about extracting an array into a bizevent field?
{
"id2": "json_with_array_json_nested",
"accountData":
[
{
"Account": "f2fafaf3a",
"Name": "John Doe",
"MediumID": "a9fjah"
},
{
"Account": "gkahfkgjnv",
"Name": "Andreas Grabner",
"MediumID": "03u6n9"
},
{
"Account": "5j2nngov8bn",
"Name": "Brian Wilson",
"MediumID": "03u5nvov94n"
}
]
}
And I wanted to grab just the Name and MediumID fields.
Using this matcher: $.accountData.[Name,MediumID] would return an array and not a string.
Would we need to just JSONParse() that field then similar to the DPL above?
@victoria has a similar question: https://community.dynatrace.com/t5/Open-Q-A/How-to-Get-Specific-Properties-from-All-Elements-in-an-A...
02 Oct 2024 01:01 PM
Yeah my only specific concern is that I do not want to capture the entire complex object into the biz event since some of it contains sensitive information. So I do not even want it to get to the point where I can parse it with DQL.