代码之家  ›  专栏  ›  技术社区  ›  Alan M

Jolt转换以删除嵌套数组

  •  0
  • Alan M  · 技术社区  · 6 月前

    您能协助我执行Jolt转换,将下面提供的JSON结构转换为所需的输出格式吗?我非常感谢您的指导或实现此转换的示例转换规范。非常感谢。 从JSON:

    [
      {
        "doc_GUID": "ae5deb48-9807-11ef-aaeb-ec2a723f4399",
        "items": [
          {
            "item_id": "00-00002475",
            "type_of_goods": "RR"
          },
          {
            "item_id": "00-00001243",
            "type_of_goods": "TT"
          },
          {
            "item_id": "00-00002997",
            "type_of_goods": "AA"
          }
        ]
      },
      {
        "doc_GUID": "e83f9131-a034-11ef-aaeb-ec2a723f4399",
        "items": [
          {
            "item_id": "00-00002828",
            "type_of_goods": "YY"
          },
          {
            "item_id": "00-000029971",
            "type_of_goods": "EE"
          }
        ]
      }
    ]
    

    对于这个结果:

    
    [
      {
        "doc_GUID": "ae5deb48-9807-11ef-aaeb-ec2a723f4399",
        "item_id": "00-00002475",
        "type_of_goods": "RR"
      },
      {
        "doc_GUID": "ae5deb48-9807-11ef-aaeb-ec2a723f4399",
        "item_id": "00-00001243",
        "type_of_goods": "TT"
      },
      {
        "doc_GUID": "ae5deb48-9807-11ef-aaeb-ec2a723f4399",
        "item_id": "00-00002997",
        "type_of_goods": "AA"
      },
      {
        "doc_GUID": "e83f9131-a034-11ef-aaeb-ec2a723f4399",
        "item_id": "00-00002828",
        "type_of_goods": "YY"
      },
      {
        "doc_GUID": "e83f9131-a034-11ef-aaeb-ec2a723f4399",
        "item_id": "00-000029971",
        "type_of_goods": "EE"
      }
    ]
    
    1 回复  |  直到 6 月前
        1
  •  0
  •   Barbaros Özhan    6 月前

    您可以在items数组的对象内循环,同时从两个上层引入doc_GUID属性,例如:

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "items": {
              "*": {
                "@2,doc_GUID": "&3_&1.doc_GUID",
                "*": "&3_&1.&"
              }
            }
          }
        }
      },
      { //get rid of the object keys
        "operation": "shift",
        "spec": {
          "*": "[]"
        }
      }
    ]
    

    这个 demo 在网站上 Jolt Transform Demo Using v0.1.1 是:

    enter image description here