Targeted JSON Pointer: for Array, RGX-Based Replacement
using Targeted JSON Pointer..
ASTER::ACTION::JSON::Targeted JSON Pointer: Is Array, Regex-based Replacement
Executes regular expression–based string replacements on all elements of a JSON array.
-
Please complete target path setting in advance.
-
Ensure that the target data type is an array.
-
Each element in the array must be of string type.
If an element is not a string, the regex replacement is skipped for that element.
{
"json.30": {
"regex_query": "^(.+)$",
"replacement": "./json/sandbox/$1.json",
"jsonArray": [
"base64_encode_test_data",
"dumptest",
"occ_params",
"regex_test"
]
}
}When the JSON path "/json.30/jsonArray" is registered in ASTER as the Targeted JSON Pointer,
the evaluated data type results in Is Array Condition being true.
Regex-based string replacements are then applied to every element in the target JSON array,
and each element is updated with the replaced string.
If an element is not a string, the replacement process is skipped.
This function is inspired by Python’s list comprehension and the concepts of map and filter.
It provides a C++ implementation that applies regular expression replacements only to string elements,
following a list-comprehension-like approach.
Using regular expressions allows for more flexible string transformations than Python’s list comprehensions.
However, as a side effect of using regex, note the following considerations:
- Requires knowledge of regular expressions (higher learning cost)
- Debugging complexity caused by regex patterns
- Performance overhead
- JSON requires UTF-8 encoding by specification
- In C++,
std::regex— especially in MSVC — is not fully UTF-8–compliant
In MSVC environments, UTF-8 text may be processed at the byte level, which can cause incorrect matches when patterns include Japanese, Chinese, or other multibyte characters.
If your regular expressions mainly involve ASCII-based patterns (\w, ^, $, _, etc.),
the current std::regex implementation is generally practical and reliable.
Parameter.1
Example of a regex search query
"^(.+)$"^(.+)$ captures the entire content of a single line — from start (^) to end ($).
- Start anchor: The caret symbol (
^) matches the start of a line. - Capturing group =
(.+): Captures one or more characters (greedy).- Greedy quantifier:
.+matches one or more of any character (except line breaks, unless dotall mode is enabled).
- Greedy quantifier:
- End anchor: The dollar sign (
$) matches the end of a line.
Parameter.2
Example of a regex replacement string
"./json/sandbox/$1.json"$1: Refers to the captured group — in this case, the entire line.
The resulting replaced string is:
./json/sandbox/occ_params.jsonResulting JSON:
{
"json.30": {
"regex_query": "^(.+)$",
"replacement": "./json/sandbox/$1.json",
"jsonArray": [
"./json/sandbox/base64_encode_test_data.json",
"./json/sandbox/dumptest.json",
"./json/sandbox/occ_params.json",
"./json/sandbox/regex_test.json"
]
}
}application screen
Example: File existence varification
CF25: Event List Editor Screen