簡體   English   中英

使用shift,默認操作進行Jolt轉換

[英]Jolt transformation using shift,default operations

Input
{
  "name": "Karan",
  "age": 25,
  "contact": {
    "email": "abc@gmail.com"
  },
  "details": [
    {
      "contact": {
        "firstName": "karan",
        "lastName": "singh"
      },
      "phone": "5555555555",
      "email": "karan@gmail.com",
      "address": {
        "line1": "123",
        "city": "bangalore",
        "state": "karnataka",
        "country": "india",
        "zip": "570089"
      }
    }
  ],
  "shippingTo": {
    "contact": {
      "name": {
        "firstName": "5505",
        "lastName": "5505"
      },
      "phone": null,
      "email": null
    },
    "address": {
      "line1": "2100 88th St",
      "city": "Mumbai",
      "state": "Maharashtra",
      "country": "India",
      "zip": "07047"
    }
  },
  "fulfillmentLines": [
    {
      "chargeDetails": [
        {
          "chargeCategory": "PRODUCT",
          "chargeName": "ItemPrice",
          "chargePerUnit": {
            "currencyAmount": 34.96,
            "currencyUnit": "USD"
          },
          "isDiscount": false,
          "taxDetails": {
            "taxPerUnit": {
              "currencyAmount": 2.4,
              "currencyUnit": "USD"
            },
            "taxPerLine": {
              "currencyAmount": 2.4,
              "currencyUnit": "USD"
            }
          }
        }
      ],
      "lineDates": {
        "minDeliveryDate": "2019-01-10T00:30:12+00:00",
        "maxDeliveryDate": "2019-02-10T00:30:12+00:00",
        "orderProcessingDate": "2019-03-10T00:30:12+00:00",
        "preciseDeliveryDate": "2019-04-17T01:30:12+00:00"
      }
    }
  ]
}

Output:
{
  "contact": {
    "name": "Karan",
    "age": 25,
    "isTestMode": false //How to set it to true if the input Json contact.email contains "abc"
  },
  "contactDetails": [  //Shud pick from "details" input json
    {
      "personalInfo": {
        "address": {
          "line1": 123,
          "city": "bangalore",
          "state": "karnataka",
          "country": "india",
          "zip": "570089",
          "isLoadingAvailable": false //How to Set it to default value false in each contactDetails list
        },
        "contact": {
          "firstName": "karan",
          "lastName": "singh",
          "completeName": "karan singh"
        },
        "phone": "5555555555",
        "email": "karan@gmail.com"
      }
    }
  ],
  "orderLines": [
    {
      "shipToAddress": { // How to pick from the same "shippingTo" input json for each orderLines list
        "address": {
          "addressLineOne": "2100 88th St",
          "city": "Mumbai",
          "countryCode": "India",
          "postalCode": "07047",
          "stateOrProvinceCode": "Maharashtra"
        },
        "name": {
          "firstName": "5505",
          "lastName": "5505"
        },
        "phone": {
          "completeNumber": null
        },
        "email": {
          "emailAddress": null
        }
      },
      "charges": [  //Shud pick from "fulfillmentLines.chargeDetails" input json
        {
          "chargeCategory": "PRODUCT",
          "chargeName": "ItemPrice",
          "chargePerUnit": {
            "currencyAmount": 0,
            "currencyUnit": "USD"
          },
          "isDiscount": false,
          "tax": [       //How to convert it to array as its an object(fulfillmentLines.0.chargeDetails.0.taxDetails) in input json
            {
              "taxName": "Tax1",  //How to Set it to default value "Tax1" in each "tax" list
              "taxPerLine": {
                "currencyAmount": 2.15,
                "currencyUnit": "USD"
              },
              "taxPerUnit": {
                "currencyAmount": 2.15,
                "currencyUnit": "USD"
              }
            }
          ]
        }
      ],
      "orderedLineDates": [ //Shud pick from "fulfillmentLines.lineDates" input json
        {
          "dateTypeId": "DELIVERY",
          "minExpectedDate":"2019-01-10T00:30:12+00:00",//Shud pick from minDeliveryDate
          "maxExpectedDate": "2019-02-10T00:30:12+00:00",//Shud pick from maxDeliveryDate
          "expectedDate": "2019-04-17T01:30:12+00:00"//Shud pick from preciseDeliveryDate
        },
        {
          "dateTypeId": "OPD",
          "requestedDate": "2019-03-10T00:30:12+00:00",//Shud pick from orderProcessingDate
          "expectedDate": "2019-03-10T00:30:12+00:00"//Shud pick from orderProcessingDate
        }
      ]
    }
  ]
}

需要顛簸規格相同。 另外請建議任何好的教程可用。 需要以下信息。 1.在列表中添加默認值2.根據其他字段的條件設置字段值3.Can字符串追加功能是否可以在JOLT中使用? 4.將對象轉換為數組

能否請您推薦JOLT規格?

我正在從這個網站學習 - http://jolt-demo.appspot.com - 幾個非常有用的例子。
第二個來源是文檔和查看問題頁面https://github.com/bazaarvoice/jolt/issues
以下是Spec,檢查它是否是你的意思,下面是一些評論 - 我希望你理解其余的:

[
  {
    "operation": "shift",
    "spec": {
      "name": "contact.name",
      "age": "contact.age",
      "contact": {
        "email": {
          "abc": { // here you check if it is "abc" value
            "#true": "contact.isTestMode" // # it makes that after it you puts default value
          },
          "*": { // and here you check any other values
            "#false": "contact.isTestMode"
          }
        }
      },
      "details": {
        "*": {
          "address": {
            "@": "contactDetails[&2].personalInfo.&",
            "#false": "contactDetails[&2].personalInfo.address.isLoadingAvailable"
          },
          "contact": "contactDetails[&1].personalInfo.&",
          "phone": "contactDetails[&1].personalInfo.phone",
          "email": "contactDetails[&1].personalInfo.email"
        }
      },
      "shippingTo": {
        "address": {
          "line1": "orderLines[#].shipToAddress.address.addressLineOne", // [#] it allows to put values to the same object
          "city": "orderLines[#].shipToAddress.address.city",
          "country": "orderLines[#].shipToAddress.address.countryCode",
          "zip": "orderLines[#].shipToAddress.address.postalCode",
          "state": "orderLines[#].shipToAddress.address.stateOrProvinceCode"
        },
        "contact": {
          "name": "orderLines[#].shipToAddress.&",
          "phone": "orderLines[#].shipToAddress.phone.completeNumber",
          "email": "orderLines[#].shipToAddress.email.emailAddress"
        }
      },
      "fulfillmentLines": {
        "*": {
          "chargeDetails": {
            "*": {
              "chargeCategory": "orderLines[#].charges[#].chargeCategory",
              "chargeName": "orderLines[#].charges[#].chargeName",
              "chargePerUnit": "orderLines[#].charges[#].&",
              "isDiscount": "orderLines[#].charges[#].isDiscount",
              "#Tax1": "orderLines[#].charges[#].tax[#].taxName",
              "taxDetails": {
                "*": "orderLines[#].charges[#].tax[#].&"
              }
            }
          },
          "lineDates": {
            "#DELIVERY": "orderLines[#].orderedLineDates[0].dateTypeId",
            "minDeliveryDate": "orderLines[#].orderedLineDates[0].minExpectedDate",
            "maxDeliveryDate": "orderLines[#].orderedLineDates[0].maxExpectedDate",
            "preciseDeliveryDate": "orderLines[#].orderedLineDates[0].expectedDate",
            "#OPD": "orderLines[#].orderedLineDates[1].dateTypeId",
            "orderProcessingDate": ["orderLines[#].orderedLineDates[1].requestedDate", "orderLines[#].orderedLineDates[1].expectedDate"]
          }
        }
      }
    }
  },
  {
    "operation": "modify-default-beta",
    "spec": {
      "contactDetails": {
        "*": {
          "personalInfo": {
            "contact": {
              "completeName": "=concat(@(1,firstName),' ',@(1,lastName))"
            }
          }
        }
      }
    }
  }
]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM