最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

json - Jolt - inserting matched field in array list - Stack Overflow

programmeradmin0浏览0评论

Below is the input i have that comes from the mergerecord processor where the erp_projectid is the correlation attribute

Input to JOLTTransformJson :

[
  {
    "priority_id": 8,
    "erp_projectid": 1383,
    "erp_subprojectid": 1496,
    "subject": "NewPhaseTest Main"
  },
  {
    "priority_id": 8,
    "erp_projectid": 1383,
    "erp_subprojectid": 1497,
    "subject": "NewPhaseTest-002"
  },
  {
    "erp_projectid": 1383,
    "erp_subprojectid": 1496,
    "project_id": 300
  }
]

Expected Output

[
  {
    "priority_id": 8,
    "erp_projectid": 1383,
    "erp_subprojectid": 1496,
    "subject": "NewPhaseTest Main",
    "project_id": 300
  },
  {
    "priority_id": 8,
    "erp_projectid": 1383,
    "erp_subprojectid": 1497,
    "subject": "NewPhaseTest-002",
    "project_id": 300
  }
]

I've tried writing a jolt spec but it is not giving me the right output ... to give a little bit context there are two executesql that gives me two flow files on which i have passed them through evaluatejsonpath to give them the erp_projectid attribute then i merge them to have one flow file for which the input i have shared and i expect them to pass through jolttransform json to get the desired output also what would be the dsl in that case and if that is not feasible how else i can achieve the output i want?

Below is the input i have that comes from the mergerecord processor where the erp_projectid is the correlation attribute

Input to JOLTTransformJson :

[
  {
    "priority_id": 8,
    "erp_projectid": 1383,
    "erp_subprojectid": 1496,
    "subject": "NewPhaseTest Main"
  },
  {
    "priority_id": 8,
    "erp_projectid": 1383,
    "erp_subprojectid": 1497,
    "subject": "NewPhaseTest-002"
  },
  {
    "erp_projectid": 1383,
    "erp_subprojectid": 1496,
    "project_id": 300
  }
]

Expected Output

[
  {
    "priority_id": 8,
    "erp_projectid": 1383,
    "erp_subprojectid": 1496,
    "subject": "NewPhaseTest Main",
    "project_id": 300
  },
  {
    "priority_id": 8,
    "erp_projectid": 1383,
    "erp_subprojectid": 1497,
    "subject": "NewPhaseTest-002",
    "project_id": 300
  }
]

I've tried writing a jolt spec but it is not giving me the right output ... to give a little bit context there are two executesql that gives me two flow files on which i have passed them through evaluatejsonpath to give them the erp_projectid attribute then i merge them to have one flow file for which the input i have shared and i expect them to pass through jolttransform json to get the desired output also what would be the dsl in that case and if that is not feasible how else i can achieve the output i want?

Share Improve this question edited Jan 19 at 12:45 Barbaros Özhan 65.2k11 gold badges36 silver badges61 bronze badges asked Jan 19 at 12:41 Sanidhya SharmaSanidhya Sharma 131 silver badge2 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can use the following shift transformations :

[
  { //accumulate the stuff under common "erp_projectid"
    //while prepare the objects without "priority_id" to be eliminated  
    "operation": "shift",
    "spec": {
      "*": {
        "project_id": "@1,erp_projectid.&",
        "*": "@1,erp_projectid.&1.@1,priority_id.&"
      }

    }
  },
  { //transfer the extracted "project_id" attribute
    //into the objects
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "*": "[#3].&",
            "@2,project_id": "[#3].project_id"
          }
        },
        "project_id": { "": "" } //get rid of the transferred attribute
      }
    }
  }
]

the demo on the site Jolt Transform Demo Using v0.1.1 is :

Edit : if you wanna keep the last object as well, as specified in the comment, then use the following one :

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "project_id": "@1,erp_projectid.&",
        "*": "@1,erp_projectid.&1.&" //remove the part ".@1,priority_id" from here
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          // "*": { reduce one layer
          "*": "[#2].&",
          "@1,project_id": "[#2].project_id"
            // }
        },
        "project_id": { "": "" }
      }
    }
  }
]
发布评论

评论列表(0)

  1. 暂无评论