Support Questions

Find answers, ask questions, and share your expertise

Need a jolt transfomation for my json input

avatar
Frequent Visitor

Experts,

Provide me jolt transform for my json input shown below

Input json would be like below. This is just one record. Actually there can be multiple records

{
"Product": "4039",
"Plant": "1010",
"MRPArea": "",
"PlndIndepRqmtType": "VSE",
"PlndIndepRqmtVersion": "00",
"RequirementPlan": "",
"RequirementSegment": "",
"PlndIndepRqmtIsActive": "X",
"PlndIndepRqmtPeriod": "20250502",
"NoWithdrawal": "",
"DeleteOld": "",
"PeriodType": "2",
"PlannedQuantity": "20.000",
"UnitOfMeasure": "PC",
"ProductionVersion": ""
}

Output what i am expecting as below

{
"Product": "4039",
"Plant": "1010",
"MRPArea": "",
"PlndIndepRqmtType": "VSE",
"PlndIndepRqmtVersion": "00",
"RequirementPlan": "",
"RequirementSegment": "",
"PlndIndepRqmtIsActive": "X",
"PlndIndepRqmtPeriod": "20250502",
"NoWithdrawal": "",
"DeleteOld": "",
"to_PlndIndepRqmtItem": [
{
"Product": "4039",
"Plant": "1010",
"MRPArea": "",
"PlndIndepRqmtType": "VSE",
"PlndIndepRqmtVersion": "00",
"RequirementPlan": "",
"RequirementSegment": "",
"PlndIndepRqmtPeriod": "20250502",
"PeriodType": "2",
"PlannedQuantity": "20.000",
"UnitOfMeasure": "PC",
"ProductionVersion": ""
}
]
}

"to_PlndIndepRqmtItem" array has some duplicate fileds from header. 

1 ACCEPTED SOLUTION

avatar
Master Mentor

@Kumar1243 

Try using the following spec:

[
  {
    "operation": "shift",
    "spec": {
      "Product": [
        "Product",
        "to_PlndIndepRqmtItem[0].Product"
      ],
      "Plant": [
        "Plant",
        "to_PlndIndepRqmtItem[0].Plant"
      ],
      "MRPArea": [
        "MRPArea",
        "to_PlndIndepRqmtItem[0].MRPArea"
      ],
      "PlndIndepRqmtType": [
        "PlndIndepRqmtType",
        "to_PlndIndepRqmtItem[0].PlndIndepRqmtType"
      ],
      "PlndIndepRqmtVersion": [
        "PlndIndepRqmtVersion",
        "to_PlndIndepRqmtItem[0].PlndIndepRqmtVersion"
      ],
      "RequirementPlan": [
        "RequirementPlan",
        "to_PlndIndepRqmtItem[0].RequirementPlan"
      ],
      "RequirementSegment": [
        "RequirementSegment",
        "to_PlndIndepRqmtItem[0].RequirementSegment"
      ],
      "PlndIndepRqmtPeriod": [
        "PlndIndepRqmtPeriod",
        "to_PlndIndepRqmtItem[0].PlndIndepRqmtPeriod"
      ],
      "PlndIndepRqmtIsActive": "PlndIndepRqmtIsActive",
      "NoWithdrawal": "NoWithdrawal",
      "DeleteOld": "DeleteOld",
      "PeriodType": "to_PlndIndepRqmtItem[0].PeriodType",
      "PlannedQuantity": "to_PlndIndepRqmtItem[0].PlannedQuantity",
      "UnitOfMeasure": "to_PlndIndepRqmtItem[0].UnitOfMeasure",
      "ProductionVersion": "to_PlndIndepRqmtItem[0].ProductionVersion"
    }
  }
]

You can use the JoltTransformRecord  or JoltTransformJson processors.  The JoltTransfromRecord will allow you to define a schema for your multi-record input FlowFiles. The JoltTransformJson processor would require you to split you source FlowFile first so you have one record per FlowFile. 

MattWho_0-1758548039881.png


Hope this helps you get closer to success,.

Please help our community grow. If you found any of the suggestions/solutions provided helped you with solving your issue or answering your question, please take a moment to login and click "Accept as Solution" on one or more of them that helped.

Thank you,
Matt

 

 

View solution in original post

1 REPLY 1

avatar
Master Mentor

@Kumar1243 

Try using the following spec:

[
  {
    "operation": "shift",
    "spec": {
      "Product": [
        "Product",
        "to_PlndIndepRqmtItem[0].Product"
      ],
      "Plant": [
        "Plant",
        "to_PlndIndepRqmtItem[0].Plant"
      ],
      "MRPArea": [
        "MRPArea",
        "to_PlndIndepRqmtItem[0].MRPArea"
      ],
      "PlndIndepRqmtType": [
        "PlndIndepRqmtType",
        "to_PlndIndepRqmtItem[0].PlndIndepRqmtType"
      ],
      "PlndIndepRqmtVersion": [
        "PlndIndepRqmtVersion",
        "to_PlndIndepRqmtItem[0].PlndIndepRqmtVersion"
      ],
      "RequirementPlan": [
        "RequirementPlan",
        "to_PlndIndepRqmtItem[0].RequirementPlan"
      ],
      "RequirementSegment": [
        "RequirementSegment",
        "to_PlndIndepRqmtItem[0].RequirementSegment"
      ],
      "PlndIndepRqmtPeriod": [
        "PlndIndepRqmtPeriod",
        "to_PlndIndepRqmtItem[0].PlndIndepRqmtPeriod"
      ],
      "PlndIndepRqmtIsActive": "PlndIndepRqmtIsActive",
      "NoWithdrawal": "NoWithdrawal",
      "DeleteOld": "DeleteOld",
      "PeriodType": "to_PlndIndepRqmtItem[0].PeriodType",
      "PlannedQuantity": "to_PlndIndepRqmtItem[0].PlannedQuantity",
      "UnitOfMeasure": "to_PlndIndepRqmtItem[0].UnitOfMeasure",
      "ProductionVersion": "to_PlndIndepRqmtItem[0].ProductionVersion"
    }
  }
]

You can use the JoltTransformRecord  or JoltTransformJson processors.  The JoltTransfromRecord will allow you to define a schema for your multi-record input FlowFiles. The JoltTransformJson processor would require you to split you source FlowFile first so you have one record per FlowFile. 

MattWho_0-1758548039881.png


Hope this helps you get closer to success,.

Please help our community grow. If you found any of the suggestions/solutions provided helped you with solving your issue or answering your question, please take a moment to login and click "Accept as Solution" on one or more of them that helped.

Thank you,
Matt