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

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

Complex JSON to flat JSON Format using JOLT required

问题

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

输入

  1. {
  2. "guid": 16161616,
  3. "WebHookId": 1234567890,
  4. "siteLocation": "offshore",
  5. "ReferenceCountry": [
  6. {
  7. "RefCountry": "DE",
  8. "Country": "DE"
  9. },
  10. {
  11. "RefCountry": "DE",
  12. "Country": "BE"
  13. },
  14. {
  15. "RefCountry": "DE",
  16. "Country": "NL"
  17. }
  18. ],
  19. "WTGLevel": [
  20. {
  21. "WTG_SCID": "/",
  22. "WTG_ReferenceCountry": "DE",
  23. "WTG_Material": "WTG_01",
  24. "WTG_Description": "CS-048948A-#01",
  25. "WTG_Quantity": 1,
  26. "WTG_UnitOfMeasure": "EA",
  27. "WTG_WTGType": "V136-4.0MW",
  28. "WTG_RotorDiameter": "136 m",
  29. "WTG_MarkRelease": "3F",
  30. "WTG_NominalEffect": 4200,
  31. "WTG_HubHeight": 112,
  32. "component": [
  33. {
  34. "Cmpt_Material": "SP_AVI_LAMP_01",
  35. "Cmpt_Description": "Site Parts Aviation Lamp MSI",
  36. "Cmpt_Quantity": 1,
  37. "Cmpt_UnitOfMeasure": "EA",
  38. "Cmpt_CapacityType": "NAC_OPT",
  39. "Cmpt_MaterialGroup": 5,
  40. "Cmpt_DerivedMaterial": 29197892,
  41. "Cmpt_MaterialIndicator": "VAR",
  42. "Cmpt_PriceBaseID": "P/AV_LA:AVWTG_3MW/AV_LA_18/AV_Q_1"
  43. },
  44. {
  45. "Cmpt_Material": "LAMP_01",
  46. "Cmpt_Description": "Lamp MSI",
  47. "Cmpt_Quantity": 5,
  48. "Cmpt_UnitOfMeasure": "fA",
  49. "Cmpt_CapacityType": "OPT",
  50. "Cmpt_MaterialGroup": 51,
  51. "Cmpt_DerivedMaterial": 88899892,
  52. "Cmpt_MaterialIndicator": "VAR",
  53. "Cmpt_PriceBaseID": "AV_LA_18/AV_Q_1"
  54. }
  55. ]
  56. },
  57. {
  58. "WTG_SCID": "zyUL6lemDdM",
  59. "WTG_ReferenceCountry": "DE",
  60. "WTG_Material": "WTG_01",
  61. "WTG_Description": "CS-042692A-#01",
  62. "WTG_Quantity": 1,
  63. "WTG_UnitOfMeasure": "EA",
  64. "WTG_WTGType": "V136-4.0MW",
  65. "WTG_RotorDiameter": "136 m",
  66. "WTG_MarkRelease": "3E",
  67. "WTG_NominalEffect": 4.2,
  68. "WTG_HubHeight": 112,
  69. "component": [
  70. {
  71. "Cmpt_Material": "DRIVE_TRAIN_01",
  72. "Cmpt_Description": "Drive Train MSI",
  73. "Cmpt_Quantity": 1,
  74. "Cmpt_UnitOfMeasure": "EA",
  75. "Cmpt_CapacityType": "DT_V136_4.0ME_3E",
  76. "Cmpt_MaterialGroup": 540,
  77. "Cmpt_DerivedMaterial": 29219265,
  78. "Cmpt_MaterialIndicator": "VAR",
  79. "Cmpt_PriceBaseID": "P/DT:P_3MW/MK_3E/R_136M/LOC_01"
  80. }
  81. ]
  82. }
  83. ]
  84. }

Jolt代码

  1. [
  2. {
  3. "operation": "shift",
  4. "spec": {
  5. "WTGLevel": {
  6. "*": {
  7. "component": {
  8. "*": {
  9. "@4,guid": "&3_&1.guid",
  10. "@4,WebHookId": "&3_&1.WebHookId",
  11. "@4,siteLocation": "&3_&1.siteLocation",
  12. "@4,ReferenceCountry.RefCountry": "&3_&1.&",
  13. "@4,ReferenceCountry.Country": "&3_&1.&",
  14. "@2,WTG_SCID": "&3_&1.WTG_SCID",
  15. "@2,WTG_ReferenceCountry": "&3_&1.WTG_ReferenceCountry",
  16. "@2,WTG_Material": "&3_&1.WTG_Material",
  17. "@2,WTG_Description": "&3_&1.WTG_Description",
  18. "@2,WTG_Quantity": "&3_&1.WTG_Quantity",
  19. "@2,WTG_UnitOfMeasure": "&3_&1.WTG_UnitOfMeasure",
  20. "@2,WTG_WTGType": "&3_&1.WTG_WTGType",
  21. "@2,WTG_RotorDiameter": "&3_&1.WTG_RotorDiameter",
  22. "@2,WTG_MarkRelease": "&3_&1.WTG_MarkRelease",
  23. "@2,WTG_NominalEffect": "&3_&1.WTG_NominalEffect",
  24. "@2,WTG_HubHeight": "&3_&1.WTG_HubHeight",
  25. "Cmpt_Material|Cmpt_Quantity|Cmpt_UnitOfMeasure|Cmpt_Description": "&3_&1.&",
  26. "Cmpt_MaterialGroup|Cmpt_DerivedMaterial|Cmpt_MaterialIndicator|CapacityType": "&3_&1.&"
  27. }
  28. }
  29. }
  30. }
  31. }
  32. },
  33. {
  34. "operation": "shift",
  35. "spec": {
  36. "*": "[]"
  37. }
  38. }
  39. ]

预期输出:9行

  1. [
  2. {
  3. "guid": 16161616,
  4. "WebHookId": 1234567890,
  5. "siteLocation": "offshore",
  6. "RefCountry": "DE",
  7. "Country": "DE",
  8. "WTG_SCID": "/",
  9. "WTG_ReferenceCountry": "DE",
  10. "WTG_Material": "WTG_01",
  11. "WTG_Description": "CS-048948A-#01",
  12. "WTG_Quantity": 1,
  13. "WTG_UnitOfMeasure": "EA",
  14. "WTG_WTGType": "V136-4.0MW",
  15. "WTG_RotorDiameter": "136 m",
  16. "WTG_MarkRelease": "3F",
  17. "WTG_NominalEffect": 4200,
  18. "WTG_HubHeight": 112,
  19. "Cmpt_Material": "SP_AVI_LAMP_01",
  20. <details>
  21. <summary>英文:</summary>
  22. 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.
  23. **Input** :
  24. ```json
  25. {
  26. &quot;guid&quot;: 16161616,
  27. &quot;WebHookId&quot;: 1234567890,
  28. &quot;siteLocation&quot;: &quot;offshore&quot;,
  29. &quot;ReferenceCountry&quot;: [
  30. {
  31. &quot;RefCountry&quot;: &quot;DE&quot;,
  32. &quot;Country&quot;: &quot;DE&quot;
  33. },
  34. {
  35. &quot;RefCountry&quot;: &quot;DE&quot;,
  36. &quot;Country&quot;: &quot;BE&quot;
  37. },
  38. {
  39. &quot;RefCountry&quot;: &quot;DE&quot;,
  40. &quot;Country&quot;: &quot;NL&quot;
  41. }
  42. ],
  43. &quot;WTGLevel&quot;: [
  44. {
  45. &quot;WTG_SCID&quot;: &quot;/&quot;,
  46. &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
  47. &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
  48. &quot;WTG_Description&quot;: &quot;CS-048948A-#01&quot;,
  49. &quot;WTG_Quantity&quot;: 1,
  50. &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
  51. &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
  52. &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
  53. &quot;WTG_MarkRelease&quot;: &quot;3F&quot;,
  54. &quot;WTG_NominalEffect&quot;: 4200,
  55. &quot;WTG_HubHeight&quot;: 112,
  56. &quot;component&quot;: [
  57. {
  58. &quot;Cmpt_Material&quot;: &quot;SP_AVI_LAMP_01&quot;,
  59. &quot;Cmpt_Description&quot;: &quot;Site Parts Aviation Lamp MSI&quot;,
  60. &quot;Cmpt_Quantity&quot;: 1,
  61. &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
  62. &quot;Cmpt_CapacityType&quot;: &quot;NAC_OPT&quot;,
  63. &quot;Cmpt_MaterialGroup&quot;: 5,
  64. &quot;Cmpt_DerivedMaterial&quot;: 29197892,
  65. &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;,
  66. &quot;Cmpt_PriceBaseID&quot;: &quot;P/AV_LA:AVWTG_3MW/AV_LA_18/AV_Q_1&quot;
  67. },
  68. {
  69. &quot;Cmpt_Material&quot;: &quot;LAMP_01&quot;,
  70. &quot;Cmpt_Description&quot;: &quot;Lamp MSI&quot;,
  71. &quot;Cmpt_Quantity&quot;: 5,
  72. &quot;Cmpt_UnitOfMeasure&quot;: &quot;fA&quot;,
  73. &quot;Cmpt_CapacityType&quot;: &quot;OPT&quot;,
  74. &quot;Cmpt_MaterialGroup&quot;: 51,
  75. &quot;Cmpt_DerivedMaterial&quot;: 88899892,
  76. &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;,
  77. &quot;Cmpt_PriceBaseID&quot;: &quot;AV_LA_18/AV_Q_1&quot;
  78. }
  79. ]
  80. },
  81. {
  82. &quot;WTG_SCID&quot;: &quot;zyUL6lemDdM&quot;,
  83. &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
  84. &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
  85. &quot;WTG_Description&quot;: &quot;CS-042692A-#01&quot;,
  86. &quot;WTG_Quantity&quot;: 1,
  87. &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
  88. &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
  89. &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
  90. &quot;WTG_MarkRelease&quot;: &quot;3E&quot;,
  91. &quot;WTG_NominalEffect&quot;: 4.2,
  92. &quot;WTG_HubHeight&quot;: 112,
  93. &quot;component&quot;: [
  94. {
  95. &quot;Cmpt_Material&quot;: &quot;DRIVE_TRAIN_01&quot;,
  96. &quot;Cmpt_Description&quot;: &quot;Drive Train MSI&quot;,
  97. &quot;Cmpt_Quantity&quot;: 1,
  98. &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
  99. &quot;Cmpt_CapacityType&quot;: &quot;DT_V136_4.0ME_3E&quot;,
  100. &quot;Cmpt_MaterialGroup&quot;: 540,
  101. &quot;Cmpt_DerivedMaterial&quot;: 29219265,
  102. &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;,
  103. &quot;Cmpt_PriceBaseID&quot;: &quot;P/DT:P_3MW/MK_3E/R_136M/LOC_01&quot;
  104. }
  105. ]
  106. }
  107. ]
  108. }

Jolt Code :

  1. [
  2. {
  3. &quot;operation&quot;: &quot;shift&quot;,
  4. &quot;spec&quot;: {
  5. &quot;WTGLevel&quot;: {
  6. &quot;*&quot;: {
  7. &quot;component&quot;: {
  8. &quot;*&quot;: { // partition the objects by indexes from two different levels
  9. &quot;@4,guid&quot;: &quot;&amp;3_&amp;1.guid&quot;,
  10. &quot;@4,WebHookId&quot;: &quot;&amp;3_&amp;1.WebHookId&quot;,
  11. &quot;@4,siteLocation&quot;: &quot;&amp;3_&amp;1.siteLocation&quot;,
  12. &quot;@4,ReferenceCountry.RefCountry&quot;: &quot;&amp;3_&amp;1.&amp;&quot;,
  13. &quot;@4,ReferenceCountry.Country&quot;: &quot;&amp;3_&amp;1.&amp;&quot;,
  14. &quot;@2,WTG_SCID&quot;: &quot;&amp;3_&amp;1.WTG_SCID&quot;,
  15. &quot;@2,WTG_ReferenceCountry&quot;: &quot;&amp;3_&amp;1.WTG_ReferenceCountry&quot;,
  16. &quot;@2,WTG_Material&quot;: &quot;&amp;3_&amp;1.WTG_Material&quot;,
  17. &quot;@2,WTG_Description&quot;: &quot;&amp;3_&amp;1.WTG_Description&quot;,
  18. &quot;@2,WTG_Quantity&quot;: &quot;&amp;3_&amp;1.WTG_Quantity&quot;,
  19. &quot;@2,WTG_UnitOfMeasure&quot;: &quot;&amp;3_&amp;1.WTG_UnitOfMeasure&quot;,
  20. &quot;@2,WTG_WTGType&quot;: &quot;&amp;3_&amp;1.WTG_WTGType&quot;,
  21. &quot;@2,WTG_RotorDiameter&quot;: &quot;&amp;3_&amp;1.WTG_RotorDiameter&quot;,
  22. &quot;@2,WTG_MarkRelease&quot;: &quot;&amp;3_&amp;1.WTG_MarkRelease&quot;,
  23. &quot;@2,WTG_NominalEffect&quot;: &quot;&amp;3_&amp;1.WTG_NominalEffect&quot;,
  24. &quot;@2,WTG_HubHeight&quot;: &quot;&amp;3_&amp;1.WTG_HubHeight&quot;,
  25. &quot;Cmpt_Material|Cmpt_Quantity|Cmpt_UnitOfMeasure|Cmpt_Description&quot;: &quot;&amp;3_&amp;1.&amp;&quot;,
  26. &quot;Cmpt_MaterialGroup|Cmpt_DerivedMaterial|Cmpt_MaterialIndicator|CapacityType&quot;: &quot;&amp;3_&amp;1.&amp;&quot;
  27. }
  28. }
  29. }
  30. }
  31. }
  32. },
  33. { // add an array wrapper at the topmost level while getting rid of newly formed object labels
  34. &quot;operation&quot;: &quot;shift&quot;,
  35. &quot;spec&quot;: {
  36. &quot;*&quot;: &quot;[]&quot;
  37. }
  38. }
  39. ]

Excepted Output : 9 rows

  1. [
  2. {
  3. &quot;guid&quot;: 16161616,
  4. &quot;WebHookId&quot;: 1234567890,
  5. &quot;siteLocation&quot;: &quot;offshore&quot;,
  6. &quot;RefCountry&quot;: &quot;DE&quot;,
  7. &quot;Country&quot;: &quot;DE&quot;,
  8. &quot;WTG_SCID&quot;: &quot;/&quot;,
  9. &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
  10. &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
  11. &quot;WTG_Description&quot;: &quot;CS-048948A-#01&quot;,
  12. &quot;WTG_Quantity&quot;: 1,
  13. &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
  14. &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
  15. &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
  16. &quot;WTG_MarkRelease&quot;: &quot;3F&quot;,
  17. &quot;WTG_NominalEffect&quot;: 4200,
  18. &quot;WTG_HubHeight&quot;: 112,
  19. &quot;Cmpt_Material&quot;: &quot;SP_AVI_LAMP_01&quot;,
  20. &quot;Cmpt_Quantity&quot;: 1,
  21. &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
  22. &quot;Cmpt_Description&quot;: &quot;Site Parts Aviation Lamp MSI&quot;,
  23. &quot;Cmpt_MaterialGroup&quot;: 5,
  24. &quot;Cmpt_DerivedMaterial&quot;: 29197892,
  25. &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  26. },
  27. {
  28. &quot;guid&quot;: 16161616,
  29. &quot;WebHookId&quot;: 1234567890,
  30. &quot;siteLocation&quot;: &quot;offshore&quot;,
  31. &quot;RefCountry&quot;: &quot;DE&quot;,
  32. &quot;Country&quot;: &quot;DE&quot;,
  33. &quot;WTG_SCID&quot;: &quot;/&quot;,
  34. &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
  35. &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
  36. &quot;WTG_Description&quot;: &quot;CS-048948A-#01&quot;,
  37. &quot;WTG_Quantity&quot;: 1,
  38. &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
  39. &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
  40. &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
  41. &quot;WTG_MarkRelease&quot;: &quot;3F&quot;,
  42. &quot;WTG_NominalEffect&quot;: 4200,
  43. &quot;WTG_HubHeight&quot;: 112,
  44. &quot;Cmpt_Material&quot;: &quot;LAMP_01&quot;,
  45. &quot;Cmpt_Quantity&quot;: 5,
  46. &quot;Cmpt_UnitOfMeasure&quot;: &quot;fA&quot;,
  47. &quot;Cmpt_Description&quot;: &quot;Lamp MSI&quot;,
  48. &quot;Cmpt_MaterialGroup&quot;: 51,
  49. &quot;Cmpt_DerivedMaterial&quot;: 88899892,
  50. &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  51. },
  52. {
  53. &quot;guid&quot;: 16161616,
  54. &quot;WebHookId&quot;: 1234567890,
  55. &quot;siteLocation&quot;: &quot;offshore&quot;,
  56. &quot;RefCountry&quot;: &quot;DE&quot;,
  57. &quot;Country&quot;: &quot;DE&quot;,
  58. &quot;WTG_SCID&quot;: &quot;zyUL6lemDdM&quot;,
  59. &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
  60. &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
  61. &quot;WTG_Description&quot;: &quot;CS-042692A-#01&quot;,
  62. &quot;WTG_Quantity&quot;: 1,
  63. &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
  64. &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
  65. &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
  66. &quot;WTG_MarkRelease&quot;: &quot;3E&quot;,
  67. &quot;WTG_NominalEffect&quot;: 4.2,
  68. &quot;WTG_HubHeight&quot;: 112,
  69. &quot;Cmpt_Material&quot;: &quot;DRIVE_TRAIN_01&quot;,
  70. &quot;Cmpt_Quantity&quot;: 1,
  71. &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
  72. &quot;Cmpt_Description&quot;: &quot;Drive Train MSI&quot;,
  73. &quot;Cmpt_MaterialGroup&quot;: 540,
  74. &quot;Cmpt_DerivedMaterial&quot;: 29219265,
  75. &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  76. },
  77. {
  78. &quot;guid&quot;: 16161616,
  79. &quot;WebHookId&quot;: 1234567890,
  80. &quot;siteLocation&quot;: &quot;offshore&quot;,
  81. &quot;RefCountry&quot;: &quot;DE&quot;,
  82. &quot;Country&quot;: &quot;BE&quot;,
  83. &quot;WTG_SCID&quot;: &quot;/&quot;,
  84. &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
  85. &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
  86. &quot;WTG_Description&quot;: &quot;CS-048948A-#01&quot;,
  87. &quot;WTG_Quantity&quot;: 1,
  88. &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
  89. &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
  90. &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
  91. &quot;WTG_MarkRelease&quot;: &quot;3F&quot;,
  92. &quot;WTG_NominalEffect&quot;: 4200,
  93. &quot;WTG_HubHeight&quot;: 112,
  94. &quot;Cmpt_Material&quot;: &quot;SP_AVI_LAMP_01&quot;,
  95. &quot;Cmpt_Quantity&quot;: 1,
  96. &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
  97. &quot;Cmpt_Description&quot;: &quot;Site Parts Aviation Lamp MSI&quot;,
  98. &quot;Cmpt_MaterialGroup&quot;: 5,
  99. &quot;Cmpt_DerivedMaterial&quot;: 29197892,
  100. &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  101. },
  102. {
  103. &quot;guid&quot;: 16161616,
  104. &quot;WebHookId&quot;: 1234567890,
  105. &quot;siteLocation&quot;: &quot;offshore&quot;,
  106. &quot;RefCountry&quot;: &quot;DE&quot;,
  107. &quot;Country&quot;: &quot;BE&quot;,
  108. &quot;WTG_SCID&quot;: &quot;/&quot;,
  109. &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
  110. &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
  111. &quot;WTG_Description&quot;: &quot;CS-048948A-#01&quot;,
  112. &quot;WTG_Quantity&quot;: 1,
  113. &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
  114. &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
  115. &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
  116. &quot;WTG_MarkRelease&quot;: &quot;3F&quot;,
  117. &quot;WTG_NominalEffect&quot;: 4200,
  118. &quot;WTG_HubHeight&quot;: 112,
  119. &quot;Cmpt_Material&quot;: &quot;LAMP_01&quot;,
  120. &quot;Cmpt_Quantity&quot;: 5,
  121. &quot;Cmpt_UnitOfMeasure&quot;: &quot;fA&quot;,
  122. &quot;Cmpt_Description&quot;: &quot;Lamp MSI&quot;,
  123. &quot;Cmpt_MaterialGroup&quot;: 51,
  124. &quot;Cmpt_DerivedMaterial&quot;: 88899892,
  125. &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  126. },
  127. {
  128. &quot;guid&quot;: 16161616,
  129. &quot;WebHookId&quot;: 1234567890,
  130. &quot;siteLocation&quot;: &quot;offshore&quot;,
  131. &quot;RefCountry&quot;: &quot;DE&quot;,
  132. &quot;Country&quot;: &quot;BE&quot;,
  133. &quot;WTG_SCID&quot;: &quot;zyUL6lemDdM&quot;,
  134. &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
  135. &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
  136. &quot;WTG_Description&quot;: &quot;CS-042692A-#01&quot;,
  137. &quot;WTG_Quantity&quot;: 1,
  138. &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
  139. &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
  140. &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
  141. &quot;WTG_MarkRelease&quot;: &quot;3E&quot;,
  142. &quot;WTG_NominalEffect&quot;: 4.2,
  143. &quot;WTG_HubHeight&quot;: 112,
  144. &quot;Cmpt_Material&quot;: &quot;DRIVE_TRAIN_01&quot;,
  145. &quot;Cmpt_Quantity&quot;: 1,
  146. &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
  147. &quot;Cmpt_Description&quot;: &quot;Drive Train MSI&quot;,
  148. &quot;Cmpt_MaterialGroup&quot;: 540,
  149. &quot;Cmpt_DerivedMaterial&quot;: 29219265,
  150. &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  151. },
  152. {
  153. &quot;guid&quot;: 16161616,
  154. &quot;WebHookId&quot;: 1234567890,
  155. &quot;siteLocation&quot;: &quot;offshore&quot;,
  156. &quot;RefCountry&quot;: &quot;DE&quot;,
  157. &quot;Country&quot;: &quot;NL&quot;,
  158. &quot;WTG_SCID&quot;: &quot;/&quot;,
  159. &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
  160. &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
  161. &quot;WTG_Description&quot;: &quot;CS-048948A-#01&quot;,
  162. &quot;WTG_Quantity&quot;: 1,
  163. &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
  164. &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
  165. &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
  166. &quot;WTG_MarkRelease&quot;: &quot;3F&quot;,
  167. &quot;WTG_NominalEffect&quot;: 4200,
  168. &quot;WTG_HubHeight&quot;: 112,
  169. &quot;Cmpt_Material&quot;: &quot;SP_AVI_LAMP_01&quot;,
  170. &quot;Cmpt_Quantity&quot;: 1,
  171. &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
  172. &quot;Cmpt_Description&quot;: &quot;Site Parts Aviation Lamp MSI&quot;,
  173. &quot;Cmpt_MaterialGroup&quot;: 5,
  174. &quot;Cmpt_DerivedMaterial&quot;: 29197892,
  175. &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  176. },
  177. {
  178. &quot;guid&quot;: 16161616,
  179. &quot;WebHookId&quot;: 1234567890,
  180. &quot;siteLocation&quot;: &quot;offshore&quot;,
  181. &quot;RefCountry&quot;: &quot;DE&quot;,
  182. &quot;Country&quot;: &quot;NL&quot;,
  183. &quot;WTG_SCID&quot;: &quot;/&quot;,
  184. &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
  185. &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
  186. &quot;WTG_Description&quot;: &quot;CS-048948A-#01&quot;,
  187. &quot;WTG_Quantity&quot;: 1,
  188. &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
  189. &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
  190. &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
  191. &quot;WTG_MarkRelease&quot;: &quot;3F&quot;,
  192. &quot;WTG_NominalEffect&quot;: 4200,
  193. &quot;WTG_HubHeight&quot;: 112,
  194. &quot;Cmpt_Material&quot;: &quot;LAMP_01&quot;,
  195. &quot;Cmpt_Quantity&quot;: 5,
  196. &quot;Cmpt_UnitOfMeasure&quot;: &quot;fA&quot;,
  197. &quot;Cmpt_Description&quot;: &quot;Lamp MSI&quot;,
  198. &quot;Cmpt_MaterialGroup&quot;: 51,
  199. &quot;Cmpt_DerivedMaterial&quot;: 88899892,
  200. &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  201. },
  202. {
  203. &quot;guid&quot;: 16161616,
  204. &quot;WebHookId&quot;: 1234567890,
  205. &quot;siteLocation&quot;: &quot;offshore&quot;,
  206. &quot;RefCountry&quot;: &quot;DE&quot;,
  207. &quot;Country&quot;: &quot;NL&quot;,
  208. &quot;WTG_SCID&quot;: &quot;zyUL6lemDdM&quot;,
  209. &quot;WTG_ReferenceCountry&quot;: &quot;DE&quot;,
  210. &quot;WTG_Material&quot;: &quot;WTG_01&quot;,
  211. &quot;WTG_Description&quot;: &quot;CS-042692A-#01&quot;,
  212. &quot;WTG_Quantity&quot;: 1,
  213. &quot;WTG_UnitOfMeasure&quot;: &quot;EA&quot;,
  214. &quot;WTG_WTGType&quot;: &quot;V136-4.0MW&quot;,
  215. &quot;WTG_RotorDiameter&quot;: &quot;136 m&quot;,
  216. &quot;WTG_MarkRelease&quot;: &quot;3E&quot;,
  217. &quot;WTG_NominalEffect&quot;: 4.2,
  218. &quot;WTG_HubHeight&quot;: 112,
  219. &quot;Cmpt_Material&quot;: &quot;DRIVE_TRAIN_01&quot;,
  220. &quot;Cmpt_Quantity&quot;: 1,
  221. &quot;Cmpt_UnitOfMeasure&quot;: &quot;EA&quot;,
  222. &quot;Cmpt_Description&quot;: &quot;Drive Train MSI&quot;,
  223. &quot;Cmpt_MaterialGroup&quot;: 540,
  224. &quot;Cmpt_DerivedMaterial&quot;: 29219265,
  225. &quot;Cmpt_MaterialIndicator&quot;: &quot;VAR&quot;
  226. }
  227. ]

答案1

得分: 0

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

  1. [
  2. {
  3. "operation": "shift",
  4. "spec": {
  5. "ReferenceCountry": {
  6. "*": {
  7. "@2,WTGLevel": {
  8. "*": {
  9. "component": {
  10. "*": { // 通过来自两个不同级别的索引对对象进行分区
  11. "@6,guid": "&4_&3_&1.guid",
  12. "@6,WebHookId": "&4_&3_&1.WebHookId",
  13. "@6,siteLocation": "&4_&3_&1.siteLocation",
  14. "@4,RefCountry": "&4_&3_&1.RefCountry",
  15. "@4,Country": "&4_&3_&1.Country",
  16. "@2,WTG_SCID": "&4_&3_&1.WTG_SCID",
  17. "@2,WTG_ReferenceCountry": "&4_&3_&1.WTG_ReferenceCountry",
  18. "@2,WTG_Material": "&4_&3_&1.WTG_Material",
  19. "@2,WTG_Description": "&4_&3_&1.WTG_Description",
  20. "@2,WTG_Quantity": "&4_&3_&1.WTG_Quantity",
  21. "@2,WTG_UnitOfMeasure": "&4_&3_&1.WTG_UnitOfMeasure",
  22. "@2,WTG_WTGType": "&4_&3_&1.WTG_WTGType",
  23. "@2,WTG_RotorDiameter": "&4_&3_&1.WTG_RotorDiameter",
  24. "@2,WTG_MarkRelease": "&4_&3_&1.WTG_MarkRelease",
  25. "@2,WTG_NominalEffect": "&4_&3_&1.WTG_NominalEffect",
  26. "@2,WTG_HubHeight": "&4_&3_&1.WTG_HubHeight",
  27. "Cmpt_Material|Cmpt_Quantity|Cmpt_UnitOfMeasure|Cmpt_Description": "&4_&3_&1.&",
  28. "Cmpt_MaterialGroup|Cmpt_DerivedMaterial|Cmpt_MaterialIndicator|CapacityType": "&4_&3_&1.&"
  29. }
  30. }
  31. }
  32. }
  33. }
  34. }
  35. }
  36. },
  37. { // 在最顶层添加一个数组包装器,同时摆脱新形成的对象标签
  38. "operation": "shift",
  39. "spec": {
  40. "*": "[]"
  41. }
  42. }
  43. ]
英文:

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

  1. [
  2. {
  3. &quot;operation&quot;: &quot;shift&quot;,
  4. &quot;spec&quot;: {
  5. &quot;ReferenceCountry&quot;: {
  6. &quot;*&quot;: {
  7. &quot;@2,WTGLevel&quot;: {
  8. &quot;*&quot;: {
  9. &quot;component&quot;: {
  10. &quot;*&quot;: { // partition the objects by indexes from two different levels
  11. &quot;@6,guid&quot;: &quot;&amp;4_&amp;3_&amp;1.guid&quot;,
  12. &quot;@6,WebHookId&quot;: &quot;&amp;4_&amp;3_&amp;1.WebHookId&quot;,
  13. &quot;@6,siteLocation&quot;: &quot;&amp;4_&amp;3_&amp;1.siteLocation&quot;,
  14. &quot;@4,RefCountry&quot;: &quot;&amp;4_&amp;3_&amp;1.RefCountry&quot;,
  15. &quot;@4,Country&quot;: &quot;&amp;4_&amp;3_&amp;1.Country&quot;,
  16. &quot;@2,WTG_SCID&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_SCID&quot;,
  17. &quot;@2,WTG_ReferenceCountry&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_ReferenceCountry&quot;,
  18. &quot;@2,WTG_Material&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_Material&quot;,
  19. &quot;@2,WTG_Description&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_Description&quot;,
  20. &quot;@2,WTG_Quantity&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_Quantity&quot;,
  21. &quot;@2,WTG_UnitOfMeasure&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_UnitOfMeasure&quot;,
  22. &quot;@2,WTG_WTGType&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_WTGType&quot;,
  23. &quot;@2,WTG_RotorDiameter&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_RotorDiameter&quot;,
  24. &quot;@2,WTG_MarkRelease&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_MarkRelease&quot;,
  25. &quot;@2,WTG_NominalEffect&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_NominalEffect&quot;,
  26. &quot;@2,WTG_HubHeight&quot;: &quot;&amp;4_&amp;3_&amp;1.WTG_HubHeight&quot;,
  27. &quot;Cmpt_Material|Cmpt_Quantity|Cmpt_UnitOfMeasure|Cmpt_Description&quot;: &quot;&amp;4_&amp;3_&amp;1.&amp;&quot;,
  28. &quot;Cmpt_MaterialGroup|Cmpt_DerivedMaterial|Cmpt_MaterialIndicator|CapacityType&quot;: &quot;&amp;4_&amp;3_&amp;1.&amp;&quot;
  29. }
  30. }
  31. }
  32. }
  33. }
  34. }
  35. }
  36. },
  37. { // add an array wrapper at the topmost level while getting rid of newly formed object labels
  38. &quot;operation&quot;: &quot;shift&quot;,
  39. &quot;spec&quot;: {
  40. &quot;*&quot;: &quot;[]&quot;
  41. }
  42. }
  43. ]

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:

确定