πŸ“Œ TIP#1: Extracting values from a JSON_ARRAY using DQL

When analyzing logs or business events that include structured payloads, it’s common to receive data in the form of a JSON_ARRAY. If your field contains this format (for example, under rs.body_result), you can extract specific values from each object in the array.

Here’s a real-world example, where the array contains market data objects with fields like symbol, currency and broadcast_time:

[
  { "symbol": "BNA6C", "currency": "EXT", "closing_price": 103, "broadcast_time": "91844" },
  { "symbol": "BNA6X", "currency": "ARS", "closing_price": 107000, "broadcast_time": "91847" },
  { "symbol": "BN2M6", "currency": "ARS", "closing_price": 0.01, "broadcast_time": "91847" },
  { "symbol": "BU4J6", "currency": "ARS", "closing_price": 101.1, "broadcast_time": "91843" }
]

To extract all broadcast_time values and get the array size, use the following DQL:

| parse rs.body_result, """JSON_ARRAY:parsed_json_elements"""
| fieldsAdd array(parsed_json_elements[][broadcast_time]), alias: array.broadcast_time
| fieldsAdd arraySize(parsed_json_elements), alias: array.broadcast_time_count

:bullseye: Use Case: Finding the latest broadcast time

If your goal is to identify the most recent broadcast (i.e., the highest broadcast_time), simply add:

| fieldsAdd arrayMax(array.broadcast_time), alias: array.broadcast_time_max

This gives you the highest value inside the broadcast_time array.

:test_tube: Real Example Output (Notebook)

After running the full query in a Dynatrace Notebook, the result looks like this:

  • array.broadcast_time: [[β€œ91840”], [β€œ91834”], [β€œ91838”], [β€œ91821”], [β€œ91842”], [β€œ91841”], [β€œ132548”], [β€œ151414”], [β€œ91822”], [β€œ91843”], [β€œ91841”], [β€œ91842”], [β€œ165520”], [β€œ91843”], [β€œ91842”], [β€œ91820”], [β€œ91824”], [β€œ91820”], [β€œ91821”], [β€œ91820”], [β€œ91843”], [β€œ91840”], [β€œ91841”], [β€œ91829”], [β€œ91845”], [β€œ91815”], [β€œ91845”], [β€œ91829”], [β€œ163735”]]
  • array.broadcast_time_count: 29
  • array.broadcast_time_max: 165520

:blue_book: Notes:

  • This method works on any JSON_ARRAY-compatible field in logs or business events.
  • You can replace broadcast_time with any other field (like symbol, currency, etc.).
  • Useful in financial feeds, external API logs, or payload inspection scenarios where the structure is consistent but the array length varies.

Hope this helps streamline your JSON parsing in Dynatrace!

6 Likes

Nice! Thank you! :money_mouth_face:

1 Like

Thanks for sharing πŸ™

1 Like