Jolt转换中含点URN字段的处理问题及正确Spec咨询
Jolt转换中含点的键名处理方案
问题背景
现有如下JSON输入:
{ "orderNo": "4800001", "resourceCode": "test", "createdBy": "27150173", "action": "R", "personId": "R", "userId": "test", "extraFields": { "a": "test", "b": "test" } }
原Jolt转换规则尝试将指定字段映射到urn:ietf:params:scim:schemas:sailpoint:1.0:LaunchedWorkflow.input下,但由于Jolt默认会把键名中的点解析为层级分隔符,导致输出出现错误的嵌套结构,且字段值映射错误。
原转换规则:
[ { "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" } ] } }
解决方案
Jolt中若键名包含点,需用方括号包裹整个键名,让Jolt将其识别为完整的字符串键,而非层级分隔符。同时修正原规则中值映射的错误指向。
正确的Jolt转换规则
[ { "operation": "shift", "spec": { "orderNo": { "#orderNo": ["urn:ietf:params:scim:schemas:sailpoint:1.0:LaunchedWorkflow"].input[0].key, "@(1)": ["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, "@(1)": ["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"]包裹目标键名,避免Jolt解析其中的点为层级分隔符。 - 使用
@(1)代替原规则中的@,@(1)表示向上遍历1层,获取当前字段(如orderNo)的实际值,修正原规则中值映射错误的问题。
验证输出
应用上述规则后,将得到符合期望的输出:input数组会正确嵌套在urn:ietf:params:scim:schemas:sailpoint:1.0:LaunchedWorkflow对象下,且字段值与输入完全匹配。
内容的提问来源于stack exchange,提问作者michael
相关产品推荐
相关产品推荐

