JOLT SPEC:转移到现有阵列

问题描述 投票:0回答:1

目前我有以下输入 JSON。 “temp”对象已添加 在默认规范的帮助下。

{
  "items" : [ {
    "description" : "myDescription",
    "attributes" : [ {
      "identifier" : "colour",
      "type" : "attribute",
      "values" : [ "DE" ],
      "hint" : "1"
    }, {
      "identifier" : "pin",
      "type" : "attribute",
      "values" : [ "4711" ],
      "hint" : "1"
    }, {
      "identifier" : "price",
      "type" : "price",
      "values" : [ "77.27" ],
      "hint" : "1"
    }, {
      "identifier" : "weight",
      "type" : "attribute",
      "values" : [ "0.47" ],
      "hint" : "1"
    }, {
      "identifier" : "status",
      "type" : "attribute",
      "values" : [ "active" ],
      "hint" : "1"
    } ]
  } ],
  "temp" : {
    "hint" : "1",
    "identifier" : "additionalDescription",
    "values" : [ {
      "lang" : "de",
      "value" : "temp"
    }, {
      "lang" : "en",
      "value" : "temp"
    }, {
      "lang" : "fr",
      "value" : "temp"
    }, {
      "lang" : "it",
      "value" : "temp"
    }, {
      "lang" : "es",
      "value" : "temp"
    } ],
    "type" : "attribute"
  }
}

所需输出:

{
  "items" : [ {
    "description" : "myDescription",
    "attributes" : [ {
      "identifier" : "colour",
      "type" : "attribute",
      "values" : [ "DE" ],
      "hint" : "1"
    }, {
      "identifier" : "pin",
      "type" : "attribute",
      "values" : [ "4711" ],
      "hint" : "1"
    }, {
      "identifier" : "price",
      "type" : "price",
      "values" : [ "77.27" ],
      "hint" : "1"
    }, {
      "identifier" : "weight",
      "type" : "attribute",
      "values" : [ "0.47" ],
      "hint" : "1"
    }, {
      "identifier" : "status",
      "type" : "attribute",
      "values" : [ "active" ],
      "hint" : "1"
    }, {
    "hint" : "1",
    "identifier" : "additionalDescription",
    "values" : [ {
      "lang" : "de",
      "value" : "myDescription"
    }, {
      "lang" : "en",
      "value" : "myDescription"
    }, {
      "lang" : "fr",
      "value" : "myDescription"
    }, {
      "lang" : "it",
      "value" : "myDescription"
    }, {
      "lang" : "es",
      "value" : "myDescription"
    } ],
    "type" : "attribute"
  } ]
  } ]
}

我正在寻找的规格应该满足两个 要求:

  1. 将“新”对象集成到属性数组中。
  2. 将值“temp”替换为描述字段的值, 可以在 json 的顶部找到。

不幸的是,我已经很难将数组正确地放入输出 json 中, 更不用说“temp”值的覆盖

[
  {
    "operation": "shift",
    "spec": {
      "items": {
        "*": {
          "description": "&2.myDescription",
          "attributes": {
            "@(3,temp)": "&3.&2.&",
            "*": "&3.&2.&"
          }
        }
      }
    }
  }
]

非常感谢任何帮助。另外,我也很高兴收到有关第一个要求的提示。每当涉及数组时,我在构建 RHS(右侧)时总是很困难。

specifications jolt
1个回答
0
投票

您需要的是在 modify 转换规范中遍历 4 层树后带来所需的属性值,例如

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "temp": {
        "values": {
          "*": {
            "value": "@(4,items[0].description)"
          }
        }
      }
    }
  }
]
© www.soinside.com 2019 - 2024. All rights reserved.