我有这样的json输入:
{
"sys_id": "651bc076db1b00107e032a9a4896192f",
"xxx_operation": "update",
"xxx_table_name": "customerservice_case"
"case": "upd12CS0001001",
"short_description": "upd12"
}
xxx_table_name
中定义了4种类型的表
我希望根据xxx_table_name
的值应用不同的映射。此外,一些字段(如xxx_operation
和sys_id
(对于所有类型的json都是通用的。
使用JSLT进行此转换的正确方法是什么?
理想情况下,将对公共字段进行转换,然后对其余字段进行特定转换。伪码:
{
"operation": .xxx_operation,
"id": .sys_id,
if (.xxx_operation == 'customerservice_case') {
// customerservice_case specific transformations here
}
else if (.xxx_operation == 'customerservice_ticket') {
// customerservice_ticket specific transformations here
}
}
感谢
您可以使用+
运算符将JSON对象合并在一起,因此您拥有的自定义代码几乎可以工作。如果你这样做:
{
"operation": .xxx_operation,
"id": .sys_id
} +
if (.xxx_operation == 'customerservice_case') {
// customerservice_case specific transformations here
}
else if (.xxx_operation == 'customerservice_ticket') {
// customerservice_ticket specific transformations here
}
它会起作用的。(我假设测试应该真正针对xxx_table_name
的值,但没关系。(