我的输入 JSON :
{
"user": {
"firstName": "abc",
"lastName": "xyz",
"email": "[email protected]"
},
"selections": [
{
"id": "123",
"person": "user",
"attributes": [
{
"attributeId": "AA",
"options": [
"11"
]
},
{
"attributeId": "BB",
"options": [
"22"
]
},
{
"attributeId": "CC",
"options": [
"33"
]
}
]
}
]
}
我的预期输出:
{
"firstName": "User firstName",
"lastName": "User lastName",
"username": "concatination of firstname and lastname",
"isActive": true,
"valueofBB": "22",
"phone": "",
"CCLinkedToUser": [
{
"id": "33",
"default": true
}
]
}
你能帮忙为此创建震动变换吗?
这样我只能获取前 2 个参数,而无法获取其他条件值。 BB 和 CC 值。这里需要一些帮助。
[
{
"operation": "shift",
"spec": {
"*": {
"firstName": "firstName",
"lastName": "lastName",
"isActive": "true",
"email": "email",
"phone": "null"
}
}
}
]
您可以使用以下转换:
[
{
"operation": "shift",
"spec": {
"user": {
"*Name": "&" // loop thruogh all the "user.*Name"
},
"#true": "isActive", // hardcoe by usng # wildcard
"selections": {
"*": {
"attributes": {
"*": {
"*": "@1,attributeId.&"
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"username": "=concat( @(1,firstName),' ',@(1,lastName) )",
"phone": "" //add an attribute with a default value
}
},
{ // tile as in the desired order
"operation": "shift",
"spec": {
"firstName|lastName|username": "&",
"isActive": "&",
"BB": {
"options": { "0": "valueof&2" } // &2 replicates 2 levels upper node, eg. "BB"
},
"phone": "&",
"CC": {
"options": { "0": "&2LinkedToUser[0].id" }, // &2 refers the literal "CC"
"#true": "&1LinkedToUser[0].default"
}
}
},
{// convert all boolean-convertible values to booleans
"operation": "modify-overwrite-beta",
"spec": {
"*": "=toBoolean",
"CCLinkedToUser": {
"*": {
"*": "=toBoolean"
}
}
}
}
]
网站上的 演示 https://jolt-demo.appspot.com/ 是: