Home > other >  Arrange value in JOLT
Arrange value in JOLT

Time:11-25

I want "externalId" field before "status" field in JOLT.

Any idea why I am getting status before externalId? Also, how do I correct it?

I want Externalid first and then status in the output

/avoid this text please

Stack overflow is saying to many code

below

/

Input

{
  "PURCHASE_ORDER_DISPATCH": {
    "MsgData": {
      "Transaction": {
        "PO_POD_HDR_EVW1": {
          "VENDOR_SETID": "WCOS",
          "PO_ID": 25052,
          "PO_POD_LN_EVW1": {
            "WG_REQ_ID": 25694,
            "PO_POD_SHP_EVW1": {
              "FREIGHT_TERMS": "FOBDEST",
              "BUSINESS_UNIT": "OFIC"
            }
          }
        }
      }
    }
  }
}

JOLT Spec-

[
    {
        "operation": "shift",
        "spec": {
            "#UPSERT": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityHeader.action",
            "*": {
                "*": {
                    "*": {
                        "*": {
                            "PO_ID": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.externalId",
                            "#APPROVED": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.status",
                            "*": {
                                "WG_REQ_ID": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.poDescription",
                                "*": {
                                    "FREIGHT_TERMS": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.deliveryTermCode"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
]

Expected Output-

{
  "integration-inbound:IntegrationDetails": {
    "integrationEntities": {
      "integrationEntity": {
        "integrationEntityHeader": {
          "action": "UPSERT"
        },
        "integrationEntityDetails": {
          "poDetails": {
             "externalId": 25052,
            "status": "APPROVED",
      
            "poHeader": {
              "poDescription": 25694,
              "deliveryTermCode": "FOBDEST"
            }
          }
        }
      }
    }
  }
}

New Input

enter image description here

CodePudding user response:

This is the exact thing you want according to your desired output:

[
  {
    "operation": "shift",
    "spec": {
      "#UPSERT": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityHeader.action",
      "*": {
        "*": {
          "*": {
            "*": {
              "PO_ID": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.externalId",
              "#APPROVED": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.status",
              "*": {
                "WG_REQ_ID": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.poDescription",
                "*": {
                  "FREIGHT_TERMS": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.deliveryTermCode"
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "integrationEntityHeader": "&3.&2.&1.&",
            "integrationEntityDetails": {
              "*": {
                "externalId": "&5.&4.&3.&2.&1.&",
                "status": "&5.&4.&3.&2.&1.&",
                "poHeader": "&5.&4.&3.&2.&1.&"
              }
            }
          }
        }
      }
    }
  }
]

Note: If you want to sort based on what exactly you want you need to know that you shouldn't use * for selecting keys. instead of that, you should use the name of the key to getting it. like the top spec you can see I wrote externalId, status, and poHeader continuously.

But I did not understand why you need to sort externalId and status in your JSON output.

enter image description here

Update: If you have an array in your output, You can add the below spec to the end for preventing an array of the same values.

,
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "*": {
          "*": {
            "*": {
              "*": {
                "status": "ONE"
              }
            }
          }
        }
      }
    }
  }
  • Related