Skip to content

Commit 5078073

Browse files
authored
Merge pull request #227892 from AbbyMSFT/workbooks
Add missing Workbooks info about JSONpath transformations
2 parents be750da + f179b1d commit 5078073

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed
19.4 KB
Loading

articles/azure-monitor/visualize/workbooks-jsonpath.md

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
---
22
title: Azure Monitor workbooks - Transform JSON data with JSONPath
3-
description: Learn how to use JSONPath in Azure Monitor workbooks to transform the results of JSON data returned by a queried endpoint to the format that you want.
3+
description: Use JSONPath in Azure Monitor workbooks to transform the JSON data results to a different data format.
44
services: azure-monitor
55
ms.workload: tbd
66
ms.tgt_pltfrm: ibiza
77
ms.topic: conceptual
8-
ms.date: 07/05/2022
8+
ms.date: 02/19/2023
99
---
1010

1111
# Use JSONPath to transform JSON data in workbooks
1212

13-
Workbooks can query data from many sources. Some endpoints, such as [Azure Resource Manager](../../azure-resource-manager/management/overview.md) or custom endpoint, can return results in JSON. If the JSON data returned by the queried endpoint isn't configured in a format that you want, JSONPath can be used to transform the results.
13+
Workbooks can query data from many sources. Some endpoints, such as [Azure Resource Manager](../../azure-resource-manager/management/overview.md) or custom endpoints can return results in JSON. If the JSON data returned by the queried endpoint is in a format that you don't want, you can use JSONPath transformation to convert the JSON to a table structure. You can then use the table to plot [workbook visualizations](./workbooks-overview.md#visualizations).
1414

15-
JSONPath is a query language for JSON that's similar to XPath for XML. Like XPath, JSONPath allows for the extraction and filtration of data out of JSON structure.
16-
17-
By using JSONPath transformation, workbook authors can convert JSON into a table structure. The table can then be used to plot [workbook visualizations](./workbooks-overview.md#visualizations).
15+
JSONPath is a query language for JSON that's similar to XPath for XML. Like XPath, JSONPath allows for the extraction and filtration of data out of the JSON structure.
1816

1917
## Use JSONPath
2018

19+
In this example, the JSON object represents a store's inventory. We're going to create a table of the store's available books listing their titles, authors, and prices.
20+
2121
1. Switch the workbook to edit mode by selecting **Edit**.
2222
1. Use the **Add** > **Add query** link to add a query control to the workbook.
2323
1. Select the data source as **JSON**.
@@ -56,9 +56,6 @@ By using JSONPath transformation, workbook authors can convert JSON into a table
5656
}
5757
}
5858
```
59-
60-
Let's assume we're given the preceding JSON object as a representation of a store's inventory. Our task is to create a table of the store's available books by listing their titles, authors, and prices.
61-
6259
1. Select the **Result Settings** tab and switch the result format to **JSON Path**.
6360
1. Apply the following JSON path settings:
6461

@@ -70,12 +67,38 @@ Let's assume we're given the preceding JSON object as a representation of a stor
7067
| Author | `$.author` |
7168
| Price | `$.price` |
7269

73-
Column IDs will be the column headers. Column JSON paths fields represent the path from the root of the table to the column value.
70+
Column IDs are the column headers. Column JSON paths fields represent the path from the root of the table to the column value.
7471

75-
1. Apply the preceding settings by selecting **Run Query**.
72+
1. Select **Run Query**.
7673

7774
![Screenshot that shows editing a query item with JSON data source and JSON path result format.](./media/workbooks-jsonpath/query-jsonpath.png)
7875

76+
## Use regular expressions to covert values
77+
78+
You may have some data that isn't in a standard format. To use that data effectively, you would want to convert that data into a standard format.
79+
80+
In this example, the published date is in YYYMMMDD format. The code interprets this value as a numeric value, not text, resulting in right-justified numbers, instead of as a date.
81+
82+
You can use the **Type**, **RegEx Match** and **Replace With** fields in the result settings to convert the result into true dates.
83+
84+
|Result setting field |Description |
85+
|---------|---------|
86+
|Type|Allows you to explicitly change the type of the value returned by the API. This field us usually left unset, but you can use this field to force the value to a different type. |
87+
|Regex Match|Allows you to enter a regular expression to take part (or parts) of the value returned by the API instead of the whole value. This field is usually combined with the **Replace With** field. |
88+
|Replace With|Use this field to create the new value along with the regular expression. If this value is empty, the default is `$&`, which is the match result of the expression. See string.replace documentation to see other values that you can use to generate other output.|
89+
90+
91+
To convert YYYMMDD format into YYYY-MM-DD format:
92+
93+
1. Select the Published row in the grid.
94+
1. In the **Type** field, select Date/Time so that the column is usable in charts.
95+
1. In the **Regex Match** field, use this regular expression: `([0-9]{4})([0-9]{2})([0-9]{2})`. This regular expression:
96+
- matches a four digit number, then a two digit number, then another two digit number.
97+
- The parentheses form capture groups to use in the next step.
98+
1.In the **Replace With**, use this regular expression: `$1-$2-$3. This expression creates a new string with each captured group, with a hyphen between them, turning "12345678" into "1234-56-78").
99+
1. Run the query again.
100+
101+
![Screenshot that shows JSONpath converted to date-time format.](./media/workbooks-jsonpath/workbooks-jsonpath-convert-date-time.png)
79102
## Next steps
80103

81104
- [Workbooks overview](./workbooks-overview.md)

0 commit comments

Comments
 (0)