将复杂的JSON转换为扁平的JSON格式需要使用JOLT。

huangapple go评论65阅读模式
英文:

Complex JSON to flat JSON Format using JOLT required

问题

我面临一个问题,需要将一个非常复杂的数组JSON输入转换为平面JSON格式。输入,Jolt转换和输出的详细信息如下。

输入

{
  "guid": 16161616,
  "WebHookId": 1234567890,
  "siteLocation": "offshore",
  "ReferenceCountry": [
    {
      "RefCountry": "DE",
      "Country": "DE"
    },
    {
      "RefCountry": "DE",
      "Country": "BE"
    },
    {
      "RefCountry": "DE",
      "Country": "NL"
    }
  ],
  "WTGLevel": [
    {
      "WTG_SCID": "/",
      "WTG_ReferenceCountry": "DE",
      "WTG_Material": "WTG_01",
      "WTG_Description": "CS-048948A-#01",
      "WTG_Quantity": 1,
      "WTG_UnitOfMeasure": "EA",
      "WTG_WTGType": "V136-4.0MW",
      "WTG_RotorDiameter": "136 m",
      "WTG_MarkRelease": "3F",
      "WTG_NominalEffect": 4200,
      "WTG_HubHeight": 112,
      "component": [
        {
          "Cmpt_Material": "SP_AVI_LAMP_01",
          "Cmpt_Description": "Site Parts Aviation Lamp MSI",
          "Cmpt_Quantity": 1,
          "Cmpt_UnitOfMeasure": "EA",
          "Cmpt_CapacityType": "NAC_OPT",
          "Cmpt_MaterialGroup": 5,
          "Cmpt_DerivedMaterial": 29197892,
          "Cmpt_MaterialIndicator": "VAR",
          "Cmpt_PriceBaseID": "P/AV_LA:AVWTG_3MW/AV_LA_18/AV_Q_1"
        },
        {
          "Cmpt_Material": "LAMP_01",
          "Cmpt_Description": "Lamp MSI",
          "Cmpt_Quantity": 5,
          "Cmpt_UnitOfMeasure": "fA",
          "Cmpt_CapacityType": "OPT",
          "Cmpt_MaterialGroup": 51,
          "Cmpt_DerivedMaterial": 88899892,
          "Cmpt_MaterialIndicator": "VAR",
          "Cmpt_PriceBaseID": "AV_LA_18/AV_Q_1"
        }
      ]
    },
    {
      "WTG_SCID": "zyUL6lemDdM",
      "WTG_ReferenceCountry": "DE",
      "WTG_Material": "WTG_01",
      "WTG_Description": "CS-042692A-#01",
      "WTG_Quantity": 1,
      "WTG_UnitOfMeasure": "EA",
      "WTG_WTGType": "V136-4.0MW",
      "WTG_RotorDiameter": "136 m",
      "WTG_MarkRelease": "3E",
      "WTG_NominalEffect": 4.2,
      "WTG_HubHeight": 112,
      "component": [
        {
          "Cmpt_Material": "DRIVE_TRAIN_01",
          "Cmpt_Description": "Drive Train MSI",
          "Cmpt_Quantity": 1,
          "Cmpt_UnitOfMeasure": "EA",
          "Cmpt_CapacityType": "DT_V136_4.0ME_3E",
          "Cmpt_MaterialGroup": 540,
          "Cmpt_DerivedMaterial": 29219265,
          "Cmpt_MaterialIndicator": "VAR",
          "Cmpt_PriceBaseID": "P/DT:P_3MW/MK_3E/R_136M/LOC_01"
        }
      ]
    }
  ]
}

Jolt代码

[
  {
    "operation": "shift",
    "spec": {
      "WTGLevel": {
        "*": {
          "component": {
            "*": {
              "@4,guid": "&3_&1.guid",
              "@4,WebHookId": "&3_&1.WebHookId",
              "@4,siteLocation": "&3_&1.siteLocation",
              "@4,ReferenceCountry.RefCountry": "&3_&1.&",
              "@4,ReferenceCountry.Country": "&3_&1.&",
              "@2,WTG_SCID": "&3_&1.WTG_SCID",
              "@2,WTG_ReferenceCountry": "&3_&1.WTG_ReferenceCountry",
              "@2,WTG_Material": "&3_&1.WTG_Material",
              "@2,WTG_Description": "&3_&1.WTG_Description",
              "@2,WTG_Quantity": "&3_&1.WTG_Quantity",
              "@2,WTG_UnitOfMeasure": "&3_&1.WTG_UnitOfMeasure",
              "@2,WTG_WTGType": "&3_&1.WTG_WTGType",
              "@2,WTG_RotorDiameter": "&3_&1.WTG_RotorDiameter",
              "@2,WTG_MarkRelease": "&3_&1.WTG_MarkRelease",
              "@2,WTG_NominalEffect": "&3_&1.WTG_NominalEffect",
              "@2,WTG_HubHeight": "&3_&1.WTG_HubHeight",
              "Cmpt_Material|Cmpt_Quantity|Cmpt_UnitOfMeasure|Cmpt_Description": "&3_&1.&",
              "Cmpt_MaterialGroup|Cmpt_DerivedMaterial|Cmpt_MaterialIndicator|CapacityType": "&3_&1.&"
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "[]"
    }
  }
]

预期输出:9行

[
  {
    "guid": 16161616,
    "WebHookId": 1234567890,
    "siteLocation": "offshore",
    "RefCountry": "DE",
    "Country": "DE",
    "WTG_SCID": "/",
    "WTG_ReferenceCountry": "DE",
    "WTG_Material": "WTG_01",
    "WTG_Description": "CS-048948A-#01",
    "WTG_Quantity": 1,
    "WTG_UnitOfMeasure": "EA",
    "WTG_WTGType": "V136-4.0MW",
    "WTG_RotorDiameter": "136 m",
    "WTG_MarkRelease": "3F",
    "WTG_NominalEffect": 4200,
    "WTG_HubHeight": 112,
    "Cmpt_Material": "SP_AVI_LAMP_01",


<details>
<summary>英文:</summary>

I am facing a problem, transforming a very complex array JSON input to a flat JSON format. The Input, Jolt Transformation &amp; output detail is given below.

**Input** :
```json
{
  &quot;guid&quot;: 16161616,
  &quot;WebHookId&quot;: 1234567890,
  &quot;siteLocation&quot;: &quot;offshore&quot;,
  &quot;ReferenceCountry&quot;: [
    {
      &quot;RefCountry&quot;: &quot;DE&quot;,
      &quot;Country&quot;: &quot;DE&quot;
    },
    {
      &quot;RefCountry&quot;: &quot;DE&quot;,
      &quot;Country&quot;: &quot;BE&quot;
    },
    {
      &quot;RefCountry&quot;: &quot;DE&quot;,
      &quot;Country&quot;: &quot;NL&quot;
    }
  ],
  &quot;WTGLevel&quot;: [
    {
      &quot;WTG_SCID&quot;: &quot;/&quot;,
      &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
      &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
      &quot;WTG_Description&quot;: &quot;CS-048948A-#01&quot;,
      &quot;WTG_Quantity&quot;: 1,
      &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
      &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
      &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
      &quot;WTG_MarkRelease&quot;: &quot;3F&quot;,
      &quot;WTG_NominalEffect&quot;: 4200,
      &quot;WTG_HubHeight&quot;: 112,
      &quot;component&quot;: [
        {
          &quot;Cmpt_Material&quot;: &quot;SP_AVI_LAMP_01&quot;,
          &quot;Cmpt_Description&quot;: &quot;Site Parts Aviation Lamp MSI&quot;,
          &quot;Cmpt_Quantity&quot;: 1,
          &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
          &quot;Cmpt_CapacityType&quot;: &quot;NAC_OPT&quot;,
          &quot;Cmpt_MaterialGroup&quot;: 5,
          &quot;Cmpt_DerivedMaterial&quot;: 29197892,
          &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;,
          &quot;Cmpt_PriceBaseID&quot;: &quot;P/AV_LA:AVWTG_3MW/AV_LA_18/AV_Q_1&quot;
        },
        {
          &quot;Cmpt_Material&quot;: &quot;LAMP_01&quot;,
          &quot;Cmpt_Description&quot;: &quot;Lamp MSI&quot;,
          &quot;Cmpt_Quantity&quot;: 5,
          &quot;Cmpt_UnitOfMeasure&quot;: &quot;fA&quot;,
          &quot;Cmpt_CapacityType&quot;: &quot;OPT&quot;,
          &quot;Cmpt_MaterialGroup&quot;: 51,
          &quot;Cmpt_DerivedMaterial&quot;: 88899892,
          &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;,
          &quot;Cmpt_PriceBaseID&quot;: &quot;AV_LA_18/AV_Q_1&quot;
        }
      ]
    },
    {
      &quot;WTG_SCID&quot;: &quot;zyUL6lemDdM&quot;,
      &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
      &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
      &quot;WTG_Description&quot;: &quot;CS-042692A-#01&quot;,
      &quot;WTG_Quantity&quot;: 1,
      &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
      &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
      &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
      &quot;WTG_MarkRelease&quot;: &quot;3E&quot;,
      &quot;WTG_NominalEffect&quot;: 4.2,
      &quot;WTG_HubHeight&quot;: 112,
      &quot;component&quot;: [
        {
          &quot;Cmpt_Material&quot;: &quot;DRIVE_TRAIN_01&quot;,
          &quot;Cmpt_Description&quot;: &quot;Drive Train MSI&quot;,
          &quot;Cmpt_Quantity&quot;: 1,
          &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
          &quot;Cmpt_CapacityType&quot;: &quot;DT_V136_4.0ME_3E&quot;,
          &quot;Cmpt_MaterialGroup&quot;: 540,
          &quot;Cmpt_DerivedMaterial&quot;: 29219265,
          &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;,
          &quot;Cmpt_PriceBaseID&quot;: &quot;P/DT:P_3MW/MK_3E/R_136M/LOC_01&quot;
        }
      ]
    }
  ]
}

Jolt Code :

[
  {
    &quot;operation&quot;: &quot;shift&quot;,
    &quot;spec&quot;: {
      &quot;WTGLevel&quot;: {
        &quot;*&quot;: {
          &quot;component&quot;: {
            &quot;*&quot;: { // partition the objects by indexes from two different levels
              &quot;@4,guid&quot;: &quot;&amp;3_&amp;1.guid&quot;,
              &quot;@4,WebHookId&quot;: &quot;&amp;3_&amp;1.WebHookId&quot;,
              &quot;@4,siteLocation&quot;: &quot;&amp;3_&amp;1.siteLocation&quot;,
              &quot;@4,ReferenceCountry.RefCountry&quot;: &quot;&amp;3_&amp;1.&amp;&quot;,
              &quot;@4,ReferenceCountry.Country&quot;: &quot;&amp;3_&amp;1.&amp;&quot;,
              &quot;@2,WTG_SCID&quot;: &quot;&amp;3_&amp;1.WTG_SCID&quot;,
              &quot;@2,WTG_ReferenceCountry&quot;: &quot;&amp;3_&amp;1.WTG_ReferenceCountry&quot;,
              &quot;@2,WTG_Material&quot;: &quot;&amp;3_&amp;1.WTG_Material&quot;,
              &quot;@2,WTG_Description&quot;: &quot;&amp;3_&amp;1.WTG_Description&quot;,
              &quot;@2,WTG_Quantity&quot;: &quot;&amp;3_&amp;1.WTG_Quantity&quot;,
              &quot;@2,WTG_UnitOfMeasure&quot;: &quot;&amp;3_&amp;1.WTG_UnitOfMeasure&quot;,
              &quot;@2,WTG_WTGType&quot;: &quot;&amp;3_&amp;1.WTG_WTGType&quot;,
              &quot;@2,WTG_RotorDiameter&quot;: &quot;&amp;3_&amp;1.WTG_RotorDiameter&quot;,
              &quot;@2,WTG_MarkRelease&quot;: &quot;&amp;3_&amp;1.WTG_MarkRelease&quot;,
              &quot;@2,WTG_NominalEffect&quot;: &quot;&amp;3_&amp;1.WTG_NominalEffect&quot;,
              &quot;@2,WTG_HubHeight&quot;: &quot;&amp;3_&amp;1.WTG_HubHeight&quot;,
              &quot;Cmpt_Material|Cmpt_Quantity|Cmpt_UnitOfMeasure|Cmpt_Description&quot;: &quot;&amp;3_&amp;1.&amp;&quot;,
              &quot;Cmpt_MaterialGroup|Cmpt_DerivedMaterial|Cmpt_MaterialIndicator|CapacityType&quot;: &quot;&amp;3_&amp;1.&amp;&quot;
            }
          }
        }
      }
    }
  },
  { // add an array wrapper at the topmost level while getting rid of newly formed object labels
    &quot;operation&quot;: &quot;shift&quot;,
    &quot;spec&quot;: {
      &quot;*&quot;: &quot;[]&quot;
    }
  }
]

Excepted Output : 9 rows

[
  {
    &quot;guid&quot;: 16161616,
    &quot;WebHookId&quot;: 1234567890,
    &quot;siteLocation&quot;: &quot;offshore&quot;,
    &quot;RefCountry&quot;: &quot;DE&quot;,
    &quot;Country&quot;: &quot;DE&quot;,
    &quot;WTG_SCID&quot;: &quot;/&quot;,
    &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
    &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
    &quot;WTG_Description&quot;: &quot;CS-048948A-#01&quot;,
    &quot;WTG_Quantity&quot;: 1,
    &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
    &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
    &quot;WTG_MarkRelease&quot;: &quot;3F&quot;,
    &quot;WTG_NominalEffect&quot;: 4200,
    &quot;WTG_HubHeight&quot;: 112,
    &quot;Cmpt_Material&quot;: &quot;SP_AVI_LAMP_01&quot;,
    &quot;Cmpt_Quantity&quot;: 1,
    &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;Cmpt_Description&quot;: &quot;Site Parts Aviation Lamp MSI&quot;,
    &quot;Cmpt_MaterialGroup&quot;: 5,
    &quot;Cmpt_DerivedMaterial&quot;: 29197892,
    &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  },
  {
    &quot;guid&quot;: 16161616,
    &quot;WebHookId&quot;: 1234567890,
    &quot;siteLocation&quot;: &quot;offshore&quot;,
    &quot;RefCountry&quot;: &quot;DE&quot;,
    &quot;Country&quot;: &quot;DE&quot;,
    &quot;WTG_SCID&quot;: &quot;/&quot;,
    &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
    &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
    &quot;WTG_Description&quot;: &quot;CS-048948A-#01&quot;,
    &quot;WTG_Quantity&quot;: 1,
    &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
    &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
    &quot;WTG_MarkRelease&quot;: &quot;3F&quot;,
    &quot;WTG_NominalEffect&quot;: 4200,
    &quot;WTG_HubHeight&quot;: 112,
    &quot;Cmpt_Material&quot;: &quot;LAMP_01&quot;,
    &quot;Cmpt_Quantity&quot;: 5,
    &quot;Cmpt_UnitOfMeasure&quot;: &quot;fA&quot;,
    &quot;Cmpt_Description&quot;: &quot;Lamp MSI&quot;,
    &quot;Cmpt_MaterialGroup&quot;: 51,
    &quot;Cmpt_DerivedMaterial&quot;: 88899892,
    &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  },
  {
    &quot;guid&quot;: 16161616,
    &quot;WebHookId&quot;: 1234567890,
    &quot;siteLocation&quot;: &quot;offshore&quot;,
    &quot;RefCountry&quot;: &quot;DE&quot;,
    &quot;Country&quot;: &quot;DE&quot;,
    &quot;WTG_SCID&quot;: &quot;zyUL6lemDdM&quot;,
    &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
    &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
    &quot;WTG_Description&quot;: &quot;CS-042692A-#01&quot;,
    &quot;WTG_Quantity&quot;: 1,
    &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
    &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
    &quot;WTG_MarkRelease&quot;: &quot;3E&quot;,
    &quot;WTG_NominalEffect&quot;: 4.2,
    &quot;WTG_HubHeight&quot;: 112,
    &quot;Cmpt_Material&quot;: &quot;DRIVE_TRAIN_01&quot;,
    &quot;Cmpt_Quantity&quot;: 1,
    &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;Cmpt_Description&quot;: &quot;Drive Train MSI&quot;,
    &quot;Cmpt_MaterialGroup&quot;: 540,
    &quot;Cmpt_DerivedMaterial&quot;: 29219265,
    &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  },
  {
    &quot;guid&quot;: 16161616,
    &quot;WebHookId&quot;: 1234567890,
    &quot;siteLocation&quot;: &quot;offshore&quot;,
    &quot;RefCountry&quot;: &quot;DE&quot;,
    &quot;Country&quot;: &quot;BE&quot;,
    &quot;WTG_SCID&quot;: &quot;/&quot;,
    &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
    &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
    &quot;WTG_Description&quot;: &quot;CS-048948A-#01&quot;,
    &quot;WTG_Quantity&quot;: 1,
    &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
    &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
    &quot;WTG_MarkRelease&quot;: &quot;3F&quot;,
    &quot;WTG_NominalEffect&quot;: 4200,
    &quot;WTG_HubHeight&quot;: 112,
    &quot;Cmpt_Material&quot;: &quot;SP_AVI_LAMP_01&quot;,
    &quot;Cmpt_Quantity&quot;: 1,
    &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;Cmpt_Description&quot;: &quot;Site Parts Aviation Lamp MSI&quot;,
    &quot;Cmpt_MaterialGroup&quot;: 5,
    &quot;Cmpt_DerivedMaterial&quot;: 29197892,
    &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  },
  {
    &quot;guid&quot;: 16161616,
    &quot;WebHookId&quot;: 1234567890,
    &quot;siteLocation&quot;: &quot;offshore&quot;,
    &quot;RefCountry&quot;: &quot;DE&quot;,
    &quot;Country&quot;: &quot;BE&quot;,
    &quot;WTG_SCID&quot;: &quot;/&quot;,
    &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
    &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
    &quot;WTG_Description&quot;: &quot;CS-048948A-#01&quot;,
    &quot;WTG_Quantity&quot;: 1,
    &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
    &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
    &quot;WTG_MarkRelease&quot;: &quot;3F&quot;,
    &quot;WTG_NominalEffect&quot;: 4200,
    &quot;WTG_HubHeight&quot;: 112,
    &quot;Cmpt_Material&quot;: &quot;LAMP_01&quot;,
    &quot;Cmpt_Quantity&quot;: 5,
    &quot;Cmpt_UnitOfMeasure&quot;: &quot;fA&quot;,
    &quot;Cmpt_Description&quot;: &quot;Lamp MSI&quot;,
    &quot;Cmpt_MaterialGroup&quot;: 51,
    &quot;Cmpt_DerivedMaterial&quot;: 88899892,
    &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  },
  {
    &quot;guid&quot;: 16161616,
    &quot;WebHookId&quot;: 1234567890,
    &quot;siteLocation&quot;: &quot;offshore&quot;,
    &quot;RefCountry&quot;: &quot;DE&quot;,
    &quot;Country&quot;: &quot;BE&quot;,
    &quot;WTG_SCID&quot;: &quot;zyUL6lemDdM&quot;,
    &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
    &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
    &quot;WTG_Description&quot;: &quot;CS-042692A-#01&quot;,
    &quot;WTG_Quantity&quot;: 1,
    &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
    &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
    &quot;WTG_MarkRelease&quot;: &quot;3E&quot;,
    &quot;WTG_NominalEffect&quot;: 4.2,
    &quot;WTG_HubHeight&quot;: 112,
    &quot;Cmpt_Material&quot;: &quot;DRIVE_TRAIN_01&quot;,
    &quot;Cmpt_Quantity&quot;: 1,
    &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;Cmpt_Description&quot;: &quot;Drive Train MSI&quot;,
    &quot;Cmpt_MaterialGroup&quot;: 540,
    &quot;Cmpt_DerivedMaterial&quot;: 29219265,
    &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  },
  {
    &quot;guid&quot;: 16161616,
    &quot;WebHookId&quot;: 1234567890,
    &quot;siteLocation&quot;: &quot;offshore&quot;,
    &quot;RefCountry&quot;: &quot;DE&quot;,
    &quot;Country&quot;: &quot;NL&quot;,
    &quot;WTG_SCID&quot;: &quot;/&quot;,
    &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
    &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
    &quot;WTG_Description&quot;: &quot;CS-048948A-#01&quot;,
    &quot;WTG_Quantity&quot;: 1,
    &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
    &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
    &quot;WTG_MarkRelease&quot;: &quot;3F&quot;,
    &quot;WTG_NominalEffect&quot;: 4200,
    &quot;WTG_HubHeight&quot;: 112,
    &quot;Cmpt_Material&quot;: &quot;SP_AVI_LAMP_01&quot;,
    &quot;Cmpt_Quantity&quot;: 1,
    &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;Cmpt_Description&quot;: &quot;Site Parts Aviation Lamp MSI&quot;,
    &quot;Cmpt_MaterialGroup&quot;: 5,
    &quot;Cmpt_DerivedMaterial&quot;: 29197892,
    &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  },
  {
    &quot;guid&quot;: 16161616,
    &quot;WebHookId&quot;: 1234567890,
    &quot;siteLocation&quot;: &quot;offshore&quot;,
    &quot;RefCountry&quot;: &quot;DE&quot;,
    &quot;Country&quot;: &quot;NL&quot;,
    &quot;WTG_SCID&quot;: &quot;/&quot;,
    &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
    &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
    &quot;WTG_Description&quot;: &quot;CS-048948A-#01&quot;,
    &quot;WTG_Quantity&quot;: 1,
    &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
    &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
    &quot;WTG_MarkRelease&quot;: &quot;3F&quot;,
    &quot;WTG_NominalEffect&quot;: 4200,
    &quot;WTG_HubHeight&quot;: 112,
    &quot;Cmpt_Material&quot;: &quot;LAMP_01&quot;,
    &quot;Cmpt_Quantity&quot;: 5,
    &quot;Cmpt_UnitOfMeasure&quot;: &quot;fA&quot;,
    &quot;Cmpt_Description&quot;: &quot;Lamp MSI&quot;,
    &quot;Cmpt_MaterialGroup&quot;: 51,
    &quot;Cmpt_DerivedMaterial&quot;: 88899892,
    &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  },
  {
    &quot;guid&quot;: 16161616,
    &quot;WebHookId&quot;: 1234567890,
    &quot;siteLocation&quot;: &quot;offshore&quot;,
    &quot;RefCountry&quot;: &quot;DE&quot;,
    &quot;Country&quot;: &quot;NL&quot;,
    &quot;WTG_SCID&quot;: &quot;zyUL6lemDdM&quot;,
    &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
    &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
    &quot;WTG_Description&quot;: &quot;CS-042692A-#01&quot;,
    &quot;WTG_Quantity&quot;: 1,
    &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
    &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
    &quot;WTG_MarkRelease&quot;: &quot;3E&quot;,
    &quot;WTG_NominalEffect&quot;: 4.2,
    &quot;WTG_HubHeight&quot;: 112,
    &quot;Cmpt_Material&quot;: &quot;DRIVE_TRAIN_01&quot;,
    &quot;Cmpt_Quantity&quot;: 1,
    &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
    &quot;Cmpt_Description&quot;: &quot;Drive Train MSI&quot;,
    &quot;Cmpt_MaterialGroup&quot;: 540,
    &quot;Cmpt_DerivedMaterial&quot;: 29219265,
    &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  }
]

答案1

得分: 0

你可以通过将其中一个数组(ReferenceCountryWTGLevel)放入 @2, 来同心地使用它们,以获得交叉连接结果(3 x 3),以返回对象数量,例如:

[
  {
    "operation": "shift",
    "spec": {
      "ReferenceCountry": {
        "*": {
          "@2,WTGLevel": {
            "*": {
              "component": {
                "*": { // 通过来自两个不同级别的索引对对象进行分区
                  "@6,guid": "&4_&3_&1.guid",
                  "@6,WebHookId": "&4_&3_&1.WebHookId",
                  "@6,siteLocation": "&4_&3_&1.siteLocation",
                  "@4,RefCountry": "&4_&3_&1.RefCountry",
                  "@4,Country": "&4_&3_&1.Country",
                  "@2,WTG_SCID": "&4_&3_&1.WTG_SCID",
                  "@2,WTG_ReferenceCountry": "&4_&3_&1.WTG_ReferenceCountry",
                  "@2,WTG_Material": "&4_&3_&1.WTG_Material",
                  "@2,WTG_Description": "&4_&3_&1.WTG_Description",
                  "@2,WTG_Quantity": "&4_&3_&1.WTG_Quantity",
                  "@2,WTG_UnitOfMeasure": "&4_&3_&1.WTG_UnitOfMeasure",
                  "@2,WTG_WTGType": "&4_&3_&1.WTG_WTGType",
                  "@2,WTG_RotorDiameter": "&4_&3_&1.WTG_RotorDiameter",
                  "@2,WTG_MarkRelease": "&4_&3_&1.WTG_MarkRelease",
                  "@2,WTG_NominalEffect": "&4_&3_&1.WTG_NominalEffect",
                  "@2,WTG_HubHeight": "&4_&3_&1.WTG_HubHeight",
                  "Cmpt_Material|Cmpt_Quantity|Cmpt_UnitOfMeasure|Cmpt_Description": "&4_&3_&1.&",
                  "Cmpt_MaterialGroup|Cmpt_DerivedMaterial|Cmpt_MaterialIndicator|CapacityType": "&4_&3_&1.&"
                }
              }
            }
          }
        }
      }
    }
  },
  { // 在最顶层添加一个数组包装器,同时摆脱新形成的对象标签
    "operation": "shift",
    "spec": {
      "*": "[]"
    }
  }
]
英文:

You can concentrically use ReferenceCountry and WTGLevel arrays by taking one of them inside while qualifying by @2, in order to get cross join result ( 3 x 3 ) for returning the number of objects such as

[
  {
    &quot;operation&quot;: &quot;shift&quot;,
    &quot;spec&quot;: {
      &quot;ReferenceCountry&quot;: {
        &quot;*&quot;: {
          &quot;@2,WTGLevel&quot;: {
            &quot;*&quot;: {
              &quot;component&quot;: {
                &quot;*&quot;: { // partition the objects by indexes from two different levels
                  &quot;@6,guid&quot;: &quot;&amp;4_&amp;3_&amp;1.guid&quot;,
                  &quot;@6,WebHookId&quot;: &quot;&amp;4_&amp;3_&amp;1.WebHookId&quot;,
                  &quot;@6,siteLocation&quot;: &quot;&amp;4_&amp;3_&amp;1.siteLocation&quot;,
                  &quot;@4,RefCountry&quot;: &quot;&amp;4_&amp;3_&amp;1.RefCountry&quot;,
                  &quot;@4,Country&quot;: &quot;&amp;4_&amp;3_&amp;1.Country&quot;,
                  &quot;@2,WTG_SCID&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_SCID&quot;,
                  &quot;@2,WTG_ReferenceCountry&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_ReferenceCountry&quot;,
                  &quot;@2,WTG_Material&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_Material&quot;,
                  &quot;@2,WTG_Description&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_Description&quot;,
                  &quot;@2,WTG_Quantity&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_Quantity&quot;,
                  &quot;@2,WTG_UnitOfMeasure&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_UnitOfMeasure&quot;,
                  &quot;@2,WTG_WTGType&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_WTGType&quot;,
                  &quot;@2,WTG_RotorDiameter&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_RotorDiameter&quot;,
                  &quot;@2,WTG_MarkRelease&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_MarkRelease&quot;,
                  &quot;@2,WTG_NominalEffect&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_NominalEffect&quot;,
                  &quot;@2,WTG_HubHeight&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_HubHeight&quot;,
                  &quot;Cmpt_Material|Cmpt_Quantity|Cmpt_UnitOfMeasure|Cmpt_Description&quot;: &quot;&amp;4_&amp;3_&amp;1.&amp;&quot;,
                  &quot;Cmpt_MaterialGroup|Cmpt_DerivedMaterial|Cmpt_MaterialIndicator|CapacityType&quot;: &quot;&amp;4_&amp;3_&amp;1.&amp;&quot;
                }
              }
            }
          }
        }
      }
    }
  },
  { // add an array wrapper at the topmost level while getting rid of newly formed object labels
    &quot;operation&quot;: &quot;shift&quot;,
    &quot;spec&quot;: {
      &quot;*&quot;: &quot;[]&quot;
    }
  }
]

huangapple
  • 本文由 发表于 2023年5月11日 15:00:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76224889.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定