【发布时间】:2022-11-23 23:42:44
【问题描述】:
我的输入有多层嵌套数组,我需要从中连接这些字段:employeeName、subject、text 以形成评论文本。然后我需要“标记”评论文本的类型”并创建一个输出,它是一个包含多个对象的单个数组数组,其中包含分组的键值对。我的规范是生成一个数组,一个对象包含一个包含多个对象的数组成员。
这是我的输入的表示
{
"accounts": [
{
"comments": [
{
"outgetcommentstext": [
{
"text": "accountObject1 comment text1"
}
],
"employeeName": "John Doe",
"subject": "acct1-obj1-subject"
},
{
"outgetcommentstext": [
{
"text": "accountObject1 comment text2"
}
],
"employeeName": "Jane Doe",
"subject": "acct1-obj2-subject"
},
{
"outgetcommentstext": [
{
"text": "accountObject1 comment text3"
}
],
"employeeName": "Jax Doe",
"subject": "acct1-obj3-subject"
}
]
},
{
"comments": [
{
"outgetcommentstext": [
{
"text": "account2-Object1 comment text1"
}
],
"employeeName": "Jill Doe",
"subject": "acct2-obj1-subject"
},
{
"outgetcommentstext": [
{
"text": "account2-Object2 comment text2"
}
],
"employeeName": "Janet Doe",
"subject": "acct2-obj2-subject"
},
{
"outgetcommentstext": [
{
"text": "account2Object3 comment text3"
}
],
"employeeName": "Jacob Doe",
"subject": "acct2-obj3-subject"
}
]
}
]
}
这是我的规格
[
{
"spec": {
"accounts": {
"*": {
"comments": {
"*": {
"outgetcommentstext": {
"*": {
"CommentText": "=concat(@(3,employeeName),'-',@(3,subject),'-',@(1,text))"
}
}
}
}
}
}
},
"operation": "modify-overwrite-beta"
},
{
"operation": "shift",
"spec": {
"accounts": {
"*": {
"comments": {
"*": {
"outgetcommentstext": {
"*": {
"CommentText": "Job.JobCommentList[&3].CommentText",
"#XYZ": "Job.JobCommentList[&3].CommentType"
}
}
}
}
}
}
}
}
]
这是我当前的输出
{
"Job" : {
"JobCommentList" : [ {
"CommentText" : [ "John Doe-acct1-obj1-subject-accountObject1 comment text1", "Jill Doe-acct2-obj1-subject-account2-Object1 comment text1" ],
"CommentType" : [ "XYZ", "XYZ" ]
}, {
"CommentText" : [ "Jane Doe-acct1-obj2-subject-accountObject1 comment text2", "Janet Doe-acct2-obj2-subject-account2-Object2 comment text2" ],
"CommentType" : [ "XYZ", "XYZ" ]
}, {
"CommentText" : [ "Jax Doe-acct1-obj3-subject-accountObject1 comment text3", "Jacob Doe-acct2-obj3-subject-account2Object3 comment text3" ],
"CommentType" : [ "XYZ", "XYZ" ]
} ]
}
}
这是我想要的输出
{
"Job": {
"JobCommentList": [
{
"CommentText": "John Doe-acct1-obj1-subject-accountObject1 comment text1",
"CommentType": "XYZ"
},
{
"CommentText": "Jill Doe-acct2-obj1-subject-account2-Object1 comment text1",
"CommentType": "XYZ"
},
{
"CommentText": "Jane Doe-acct1-obj2-subject-accountObject1 comment text2",
"CommentType": "XYZ"
},
{
"CommentText": "Jacob Doe-acct2-obj3-subject-account2Object3 comment text3",
"CommentType": "XYZ"
}
]
}
}
请注意,我的输入可能有一个或多个帐户对象。我发现如果只有一个帐户对象,我的规范就可以工作
【问题讨论】:
标签: nested-lists jolt