我有以下 JSON,我想用 Jolt 转换它。
JSON 输入
{
"orderNo": "4800001",
"resourceCode": "test",
"createdBy": "27150173",
"action": "R",
"personId": "R",
"userId": "test",
"extraFields": {
"a": "test",
"b": "test"
}
}
Jolt Transform 尝试过
[
{
"operation": "shift",
"spec": {
"orderNo": {
"#orderNo": "urn:ietf:params:scim:schemas:sailpoint:1.0:LaunchedWorkflow.input[0].key",
"@": "urn:ietf:params:scim:schemas:sailpoint:1.0:LaunchedWorkflow.input[0].value"
},
"createdBy": {
"#identityName": "urn:ietf:params:scim:schemas:sailpoint:1.0:LaunchedWorkflow.input[1].key",
"@": "urn:ietf:params:scim:schemas:sailpoint:1.0:LaunchedWorkflow.input[1].value"
}
}
},
{
"operation": "default",
"spec": {
"schemas": [
"urn:ietf:params:scim:schemas:sailpoint:1.0:LaunchedWorkflow",
"urn:ietf:params:scim:schemas:sailpoint:1.0:TaskResult"
],
"urn:ietf:params:scim:schemas:sailpoint:1.0:LaunchedWorkflow": {
"workflowName": "Fix"
}
}
}
]
电流输出
{
"urn:ietf:params:scim:schemas:sailpoint:1": {
"0:LaunchedWorkflow": {
"input": [
{
"key": "orderNo",
"value": "test"
},
{
"key": "identityName",
"value": "test"
}
]
}
},
"schemas": [
"urn:ietf:params:scim:schemas:sailpoint:1.0:LaunchedWorkflow",
"urn:ietf:params:scim:schemas:sailpoint:1.0:TaskResult"
],
"urn:ietf:params:scim:schemas:sailpoint:1.0:LaunchedWorkflow": {
"workflowName": "Fix"
}
}
期望输出
{
"schemas": [
"urn:ietf:params:scim:schemas:sailpoint:1.0:LaunchedWorkflow",
"urn:ietf:params:scim:schemas:sailpoint:1.0:TaskResult"
],
"urn:ietf:params:scim:schemas:sailpoint:1.0:LaunchedWorkflow": {
"workflowName": "Fix",
"input": [
{
"key": "orderNo",
"value": "4800001"
},
{
"key": "identityName",
"value": "27150173"
}
]
}
}
问题是,我不知道如何处理里面的点"urn:ietf:params:scim:schemas:sailpoint:1.0:LaunchedWorkflow"
,所以它会充当字符串(并且不会因为点而切断它)。Jolt 规范应该是什么?
需要使用双反斜杠(
\\
)才能转义点等特殊字符。因此,您可以按如下方式重写规范:网站上的演示Jolt Transform Demo Using v0.1.1是:
事实上,仅使用这样的移位变换就足够了:
请注意,如果表达式位于右侧并以 #(固定)为前缀,则不需要对特殊字符进行转义
顺便说一句,如果orderNo和createdBy两个键都精确复制,那么更简洁的代码(其中索引不是像 和 那样一个接一个地写入,
[0]
并且[1]
更少的硬编码)就足够了,例如从而得到输出
对我来说,加倍
\
是有效的,就像这样:如果这是您要找的东西,请告诉我。