当前位置: 首页 > 知识库问答 >
问题:

使用shift的Jolt转换,默认操作

松刚豪
2023-03-14
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.字符串附加功能可以在JOLT中工作吗?4.将对象转换为数组

你能建议同样的JOLT规范吗?

共有1个答案

韦寒
2023-03-14


第二个来源是留档和查看页面上的问题https://github.com/bazaarvoice/jolt/issues
下面是规范,检查它是否是你的,下面是一些评论-我希望你理解其余的:

[
  {
    "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))"
            }
          }
        }
      }
    }
  }
]
 类似资料:
  • 我正在尝试使用JOLT进行JSON转换,我想我已经很接近了,但是我不能做的是为每个当前没有出现的字段添加一个新字段。 我已经阅读了很多教程,下面的代码是我希望能够工作的。然而,它似乎没有添加到新的“名称”字段中。 这是我的震撼: 这是输出: 我希望它是这样的: 谁能告诉我哪里出错了?显然,默认值用于添加新项目,但它似乎没有执行任何操作。

  • 我正在尝试使用JOLT(使用NiFi JoltTransformJson处理器)将JSON转换为不同的格式。对于单个JSON记录,正在使用的JOLT在JOLT应用程序演示中运行良好,而如果我使用多个JSON记录执行,那么我在JOLT应用程序演示中没有得到预期的输出。有人能告诉我在JOLT规范中需要做哪些额外的更改来处理多个JSON记录吗? 示例输入json JOLT使用: 预期输出JSON:

  • 本文向大家介绍SpringBoot2使用Jetty容器操作(替换默认Tomcat),包括了SpringBoot2使用Jetty容器操作(替换默认Tomcat)的使用技巧和注意事项,需要的朋友参考一下 Jetty和tomcat的比较 Tomcat和Jetty都是一种Servlet引擎,他们都支持标准的servlet规范和JavaEE的规范。 架构比较 Jetty的架构比Tomcat的更为简单 Jet

  • `我有以下输入json格式,需要转换以下json文件。我正在使用jolt转换,但无法使用https://jolt-demo.appspot.com/#inception网站正确格式化输出 `需要以下使用JOLT Iam的输出json格式,尝试使用JOLT转换进行转换

  • 我想转换这个JSON: 对此JSON: 我目前正在使用该规范,但它不适合我: 有人能给出一个规范吗?有没有关于jolt JSON的明确文档 ................................................................................................................................

  • 尝试转换如下内容时,我为转换后的对象获取了一个空值: 对此: 这是我使用的规范: 这是我使用的代码: 我能够使用与上述相同的规范和代码成功转换以下输入: 那么,我需要做什么来转换员工对象数组呢?