<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question JOLT to flatten nested JSON with optional nodes in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/JOLT-to-flatten-nested-JSON-with-optional-nodes/m-p/389437#M246983</link>
    <description>&lt;P&gt;Hi All&lt;/P&gt;&lt;P&gt;We are receiving data in JSON format (Nested and optional Nodes). I have written a JOLT to transform/flatten this JSON but not able to get desired result.&lt;/P&gt;&lt;P&gt;I need help to fix JOLT to get desired output.&lt;/P&gt;&lt;P&gt;Input JSON - Node - PartnerFunction and Indicator are optional.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "CustomerMaster": {
    "Rootnode": {
      "KUNNR": "0000028790",
      "NAME1": "NV Solucious",
      "LAND1": "BE",
      "SalesArea": [
        {
          "VKORG": "0200",
          "VTWEG": "00",
          "SPART": "00"
        },
        {
          "VKORG": "4932",
          "VTWEG": "00",
          "SPART": "00",
          "AUFSD1": "FT",
          "PartnerFunction": [
            {
              "PARVW": "ZP",
              "PARZA": "000",
              "KUNN2": "0000028790"
            },
            {
              "PARVW": "ZS",
              "PARZA": "000",
              "KUNN2": "90010523"
            }
          ]
        },
        {
          "VKORG": "4932",
          "VTWEG": "10",
          "SPART": "00",
          "Indicator": {
            "IsDistributionCenter": "X"
          },
          "PartnerFunction": {
            "PARVW": "ZS",
            "PARZA": "000",
            "KUNN2": "90010523"
          }
        }
      ]
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Desired Output -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;[ {
  "KUNNR": "0000028790",
  "NAME1": "NV Solucious",
  "LAND1": "BE",,
  "VKORG": "0200",
  "VTWEG": "00",
  "SPART": "00",
}, {
  "KUNNR" : "0000028790",
  "NAME1" : "NV Solucious",
  "LAND1" : "BE",
  "VKORG" : "0200",
  "VTWEG" : "00",
  "SPART" : "00",
  "AUFSD1": "FT",
  "PARVW": "ZP",
  "PARZA": "000",
  "KUNN2": "0000028790"
}, {
  "KUNNR" : "0000028790",
  "NAME1" : "NV Solucious",
  "LAND1" : "BE",
  "VKORG" : "0200",
  "VTWEG" : "00",
  "SPART" : "00",
  "AUFSD1": "FT",
  "PARVW": "ZS",
  "PARZA": "000",
  "KUNN2": "90010523"
}, {
  "KUNNR" : "0000028790",
  "NAME1" : "NV Solucious",
  "LAND1" : "BE",
  "VKORG" : "4932",
  "VTWEG" : "10",
  "SPART" : "00",
  "IsDistributionCenter": "X",
  "PARVW": "ZS",
  "PARZA": "000",
  "KUNN2": "90010523"
}]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JOLT Created so far -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;[
  {
    "operation": "shift",
    "spec": {
      "CustomerMaster": {
        "Rootnode": {
          "*": "else1.&amp;amp;",
          "SalesArea": {
            "*": {
              "*": "&amp;amp;1.else2.&amp;amp;",
              "Indicator": {       //Added the indicator field
                "*": "&amp;amp;2.else2.&amp;amp;"
              },
              "PartnerFunction": {
                "*": {
                  "*": "&amp;amp;3.&amp;amp;2[&amp;amp;1].&amp;amp;"
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "PartnerFunction": {
          "*": {
            "@(3,else1)": { "*": "&amp;amp;4[&amp;amp;1].&amp;amp;" },
            "@(2,else2)": { "*": "&amp;amp;4[&amp;amp;1].&amp;amp;" },
            "*": "&amp;amp;3[&amp;amp;1].&amp;amp;"
          }
        }
      }
    }
  },
  { // get rid of the outermost keys
    "operation": "shift",
    "spec": {
      "*": {
        "*": ""
      }
    }
  }
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using this JOLT , I am getting this output which is not the desired output.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WanderingT_0-1718874505155.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41018i6A57A2A4D4CDB507/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WanderingT_0-1718874505155.png" alt="WanderingT_0-1718874505155.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jun 2024 09:09:40 GMT</pubDate>
    <dc:creator>WanderingT</dc:creator>
    <dc:date>2024-06-20T09:09:40Z</dc:date>
    <item>
      <title>JOLT to flatten nested JSON with optional nodes</title>
      <link>https://community.cloudera.com/t5/Support-Questions/JOLT-to-flatten-nested-JSON-with-optional-nodes/m-p/389437#M246983</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;&lt;P&gt;We are receiving data in JSON format (Nested and optional Nodes). I have written a JOLT to transform/flatten this JSON but not able to get desired result.&lt;/P&gt;&lt;P&gt;I need help to fix JOLT to get desired output.&lt;/P&gt;&lt;P&gt;Input JSON - Node - PartnerFunction and Indicator are optional.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "CustomerMaster": {
    "Rootnode": {
      "KUNNR": "0000028790",
      "NAME1": "NV Solucious",
      "LAND1": "BE",
      "SalesArea": [
        {
          "VKORG": "0200",
          "VTWEG": "00",
          "SPART": "00"
        },
        {
          "VKORG": "4932",
          "VTWEG": "00",
          "SPART": "00",
          "AUFSD1": "FT",
          "PartnerFunction": [
            {
              "PARVW": "ZP",
              "PARZA": "000",
              "KUNN2": "0000028790"
            },
            {
              "PARVW": "ZS",
              "PARZA": "000",
              "KUNN2": "90010523"
            }
          ]
        },
        {
          "VKORG": "4932",
          "VTWEG": "10",
          "SPART": "00",
          "Indicator": {
            "IsDistributionCenter": "X"
          },
          "PartnerFunction": {
            "PARVW": "ZS",
            "PARZA": "000",
            "KUNN2": "90010523"
          }
        }
      ]
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Desired Output -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;[ {
  "KUNNR": "0000028790",
  "NAME1": "NV Solucious",
  "LAND1": "BE",,
  "VKORG": "0200",
  "VTWEG": "00",
  "SPART": "00",
}, {
  "KUNNR" : "0000028790",
  "NAME1" : "NV Solucious",
  "LAND1" : "BE",
  "VKORG" : "0200",
  "VTWEG" : "00",
  "SPART" : "00",
  "AUFSD1": "FT",
  "PARVW": "ZP",
  "PARZA": "000",
  "KUNN2": "0000028790"
}, {
  "KUNNR" : "0000028790",
  "NAME1" : "NV Solucious",
  "LAND1" : "BE",
  "VKORG" : "0200",
  "VTWEG" : "00",
  "SPART" : "00",
  "AUFSD1": "FT",
  "PARVW": "ZS",
  "PARZA": "000",
  "KUNN2": "90010523"
}, {
  "KUNNR" : "0000028790",
  "NAME1" : "NV Solucious",
  "LAND1" : "BE",
  "VKORG" : "4932",
  "VTWEG" : "10",
  "SPART" : "00",
  "IsDistributionCenter": "X",
  "PARVW": "ZS",
  "PARZA": "000",
  "KUNN2": "90010523"
}]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JOLT Created so far -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;[
  {
    "operation": "shift",
    "spec": {
      "CustomerMaster": {
        "Rootnode": {
          "*": "else1.&amp;amp;",
          "SalesArea": {
            "*": {
              "*": "&amp;amp;1.else2.&amp;amp;",
              "Indicator": {       //Added the indicator field
                "*": "&amp;amp;2.else2.&amp;amp;"
              },
              "PartnerFunction": {
                "*": {
                  "*": "&amp;amp;3.&amp;amp;2[&amp;amp;1].&amp;amp;"
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "PartnerFunction": {
          "*": {
            "@(3,else1)": { "*": "&amp;amp;4[&amp;amp;1].&amp;amp;" },
            "@(2,else2)": { "*": "&amp;amp;4[&amp;amp;1].&amp;amp;" },
            "*": "&amp;amp;3[&amp;amp;1].&amp;amp;"
          }
        }
      }
    }
  },
  { // get rid of the outermost keys
    "operation": "shift",
    "spec": {
      "*": {
        "*": ""
      }
    }
  }
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using this JOLT , I am getting this output which is not the desired output.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WanderingT_0-1718874505155.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/41018i6A57A2A4D4CDB507/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WanderingT_0-1718874505155.png" alt="WanderingT_0-1718874505155.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 09:09:40 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/JOLT-to-flatten-nested-JSON-with-optional-nodes/m-p/389437#M246983</guid>
      <dc:creator>WanderingT</dc:creator>
      <dc:date>2024-06-20T09:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: JOLT to flatten nested JSON with optional nodes</title>
      <link>https://community.cloudera.com/t5/Support-Questions/JOLT-to-flatten-nested-JSON-with-optional-nodes/m-p/389441#M246984</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/111200"&gt;@WanderingT&lt;/a&gt;,&amp;nbsp;Welcome to our community! To help you get the best possible answer, I have tagged in our NiFi experts&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/35454"&gt;@MattWho&lt;/a&gt;&amp;nbsp; who may be able to assist you further.&lt;BR /&gt;&lt;BR /&gt;Please feel free to provide any additional information or details about your query, and we hope that you will find a satisfactory solution to your question.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 14:32:14 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/JOLT-to-flatten-nested-JSON-with-optional-nodes/m-p/389441#M246984</guid>
      <dc:creator>VidyaSargur</dc:creator>
      <dc:date>2024-06-20T14:32:14Z</dc:date>
    </item>
  </channel>
</rss>

