This codec extracts the JSON element from the JSON request as per the JSONPATH defined.
Consider the following sample input that will be processed using the JSON codec to extract a unique JSON element:
{
"entities":[
{
"entity_type":"CostCenter",
"properties":{
"Id":"10097",
"LastUpdateTime":1455383881190,
"Currency":"USD",
"ApproveThresholdAmount":100000,
"AccountingCode":"5555",
"CostCenterAttachments":"{\"complexTypeProperties\":[]}"
}
}
],
"operation":"UPDATE"
}
In the Extract rule, assuming that the AccountingCode needs to be protected, the JSONPath that will be set is entities[*].properties.AccountingCode. Based on the input JSON structure, the JSONPath value differs.
The following figure illustrates the JSON payload fields.
The properties for the JSON payload are explained in the following tab
Properties | Sub-Field | Description |
---|---|---|
JSONPath | This JSON element value to be extracted is specified in the JSON path. Note: Ensure that you enter the JSONPath by following proper syntax for extracting the JSON element value. If you enter incorrect syntax, then the service which has this JSON payload definition in the rule fails to load and process the request. | |
Allow Empty String | Enable to pass values that are defined as only whitespaces, such as, value: " “, that are part of the JSON payload and continue processing of the sequential rules. If this check box is disabled, then the Extract rule does not process values that are defined as only whitespaces. | |
Preserve Element Order | Select to preserve the order of key-value pairs in the JSON response. | |
Fail Transaction | Select to fail transaction when an error is encountered during tokenization. The error might occur due to use of incorrect token element to protect input data. For example, when handling integer input data, the accurate token element would be an integer token element. The DSG uses tokenization logic to perform data protection. This logic can work to its optimum only if the correct token element is used to protect the input data. If you fail to perform careful analysis of your input data and identify the accurate token element that must be used, then it will result in issues when data is protected using the tokenization logic. To avoid this issue, it is recommended that before defining rules, analyze the input data and identify the accurate token element to be used to protect the data. For more information about identifying the token element that will best suit the input data, refer to Protegrity Protection Methods Reference Guide 9.0.0.0. | |
Minimize Output | Select to minify the JSON response. The JSON response is displayed in a compact form as opposed to the indented JSON response that the DSG sends. Note: It is recommended that this option is selected when the JSON input includes deeply nested key-value pairs. | |
Process Mode | Select to parse JSON data types. This field includes the following three options:
| |
Complex - Stringify | Select to process the complex JSON data type, such as, arrays and objects, to string values and serializing to JSON values before being passed to the child rule. This option is displayed by default. | |
Simple - Primitive | Select to process primitive data types, namely, string, int, float, and boolean. It does not support the processing of complex data types, such as, arrays and objects when it matches the JSON data type; the processing fails and an error message is displayed. | |
Complex - Recurse | Select to process the complex JSON data type and iterate through the JSON array or object recursively. |
The following table describes the additional configuration option for the Recurse mode.
Options | Description | Default |
---|---|---|
recurseMaxDepth | Maximum recursion depth that can be set for iterating matched arrays or objects. CAUTION: This parameter comes in effect only when the Complex - Recurse mode is selected. It is not supported for the Complex - Stringify and the Simple - Primitive modes. | 25 |
This section provides guidance on the type of JSONPath expressions that DSG understands. This guidance must be considered before you define the acceptable JSONPath to be extracted when using the JSON codec.
The DSG supports the following operators.
CAUTION: The
$
operator is not supported.
Operator | Description | Example |
---|---|---|
* | Wildcard to select all elements in scope. | foo.*.baz ["foo"][*]["baz"] |
/docs | Skip any number of elements in path. | foo/docsbaz |
[] | Access arrays or names with spaces in them. | ["foo"]["bar"]["baz"] array[-1].attr [3] |
array[1:-1:2] | Slicing arrays. | array[1:-1:2] |
=, >, <, >=, <= and != | Filter using these elements. | foo(bar.baz=true) foo.bar(baz>0).baz foo(bar="yawn").bar |
To understand the JSONPath, consider the following example JSON. The subsequent table provides JSONPath examples that can be used with the example JSON.
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "J. R. R. Rowling",
"title": "Harry Potter and Chamber of Secrets",
"isbn": "0-395-12345-8",
"price": 29.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien ",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
},
{
"category": "fiction",
"author": "Arthur Conan Doyle ",
"title": "Sherlock Homes",
"isbn": "0-795-19395-8",
"price": 9
}
]
}
}
The following table provides the JSONPath examples based on the JSON example.
JSONPath | Description | Notes |
---|---|---|
store/docstitle | All titles are displayed. | The given JSONPath examples are different in construct but provide the same result. |
store.book[*].title | ||
store.book/docstitle | ||
["store"]["book"][*]["title"] | ||
store.book[0].title | The first title is displayed. | The given JSONPath examples are different in construct but provide the same result. |
["store"]["book"][0]["title"] | ||
store.book[1:-1].title | All titles except first and last title are displayed. | The given JSONPath examples are different in construct but provide the same result. |
["store"]["book"][1:-1]["title"] | ||
["store"]["book"](price>=9)["title"] | All titles with book price greater than or equal to 9 or 9.0. | |
["store"]["book"](price>9)["title"] | All titles with book price greater than 9 or 9.0. | |
["store"]["book"](price<9)["title"] | All titles with book price less than 9 or 9.0. | |
["store"]["book"](price<=9)["title"] | All titles with book price less than or equal to 9 or 9.0. |