<?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 Re: Converting Nested JSON to Flat JSON using JOLT in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Converting-Nested-JSON-to-Flat-JSON-using-JOLT/m-p/398979#M250353</link>
    <description>&lt;P&gt;Also, FYI I have tried using this JOLT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "getCarListing": {
          "edges": {
            "*": {
              "node": {
                "carClusterIds": {
                  "*": {
                    "element": {
                      "businessRelations": {
                        "*": {
                          "countries": {
                            "*": {
                              "countryCode": "[&amp;amp;6].[&amp;amp;1].CountryCode",
                              "@(2,code)": "[&amp;amp;6].[&amp;amp;1].BR",
                              "@(4,name)": "[&amp;amp;6].[&amp;amp;1].Element"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
 },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "@": "[]"
          }
        }
      }
    }
    }

]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which is giving output in the form:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[ [ "US01", "CZ01", "CA01", "FR01", "DE01" ], [ "SEDAN1000", "SEDAN1000", "SEDAN1000", "TRUCK500", "TRUCK500" ], [ "US", "CZ", "CA", "FR", "DE" ], "CZ01", "SEDAN1000", "SK", [ "MX01", "JP01" ], [ "SUV2020", "COUPE3000" ], [ "MX", "JP" ] ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which is closer to the expected output but need some formatting.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Dec 2024 13:55:43 GMT</pubDate>
    <dc:creator>Sid17</dc:creator>
    <dc:date>2024-12-17T13:55:43Z</dc:date>
    <item>
      <title>Converting Nested JSON to Flat JSON using JOLT</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Converting-Nested-JSON-to-Flat-JSON-using-JOLT/m-p/398976#M250352</link>
      <description>&lt;P&gt;Hi team,&lt;/P&gt;&lt;P&gt;I'm struggling while converting nested JSON to Flat JSON using JOLT.&lt;/P&gt;&lt;P&gt;The Nested JSON is in the below format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
  "data": {
    "getCarListing": {
      "edges": [
        {
          "node": {
            "id": "1001",
            "identifier": 500001,
            "carClusterIds": [
              {
                "element": {
                  "name": "SEDAN1000",
                  "businessRelations": [
                    {
                      "countries": [
                        {
                          "countryCode": "US"
                        }
                      ],
                      "code": "US01"
                    },
                    {
                      "countries": [
                        {
                          "countryCode": "CZ"
                        },
                        {
                          "countryCode": "SK"
                        }
                      ],
                      "code": "CZ01"
                    },
                    {
                      "countries": [
                        {
                          "countryCode": "CA"
                        }
                      ],
                      "code": "CA01"
                    }
                  ]
                },
                "metadata": [
                  {
                    "name": "clusterId",
                    "value": "200011"
                  }
                ]
              },
              {
                "element": {
                  "name": "SUV2020",
                  "businessRelations": [
                    {
                      "countries": [
                        {
                          "countryCode": "MX"
                        }
                      ],
                      "code": "MX01"
                    }
                  ]
                },
                "metadata": [
                  {
                    "name": "clusterId",
                    "value": "200012"
                  }
                ]
              }
            ],
            "parentItems": [
              {
                "identifier": 400050
              }
            ]
          }
        },
        {
          "node": {
            "id": "1002",
            "identifier": 500002,
            "carClusterIds": [
              {
                "element": {
                  "name": "TRUCK500",
                  "businessRelations": [
                    {
                      "countries": [
                        {
                          "countryCode": "FR"
                        }
                      ],
                      "code": "FR01"
                    },
                    {
                      "countries": [
                        {
                          "countryCode": "DE"
                        }
                      ],
                      "code": "DE01"
                    }
                  ]
                },
                "metadata": [
                  {
                    "name": "clusterId",
                    "value": "200021"
                  }
                ]
              },
              {
                "element": {
                  "name": "COUPE3000",
                  "businessRelations": [
                    {
                      "countries": [
                        {
                          "countryCode": "JP"
                        }
                      ],
                      "code": "JP01"
                    }
                  ]
                },
                "metadata": [
                  {
                    "name": "clusterId",
                    "value": "200022"
                  }
                ]
              }
            ],
            "parentItems": [
              {
                "identifier": 400051
              }
            ]
          }
        }
      ]
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the output in this format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "Element" : "SEDAN1000",
    "BR" : "US01",
    "CountryCode" : "US"
  },
  {
    "Element" : "SEDAN1000",
    "BR" : "CZ01",
    "CountryCode" : "CZ"
  },
  {
    "Element" : "SEDAN1000",
    "BR" : "CZ01",
    "CountryCode" : "SK"
  },
  {
    "Element" : "SEDAN1000",
    "BR" : "CA01",
    "CountryCode" : "CA"
  },
  {
    "Element" : "SUV2020",
    "BR" : "MX01",
    "CountryCode" : "MX"
  }
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone please help me with the JOLT spec that can be used to derive the nested JSON to the required Flat JSON.&lt;/P&gt;&lt;P&gt;Thanks in Advance...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2024 12:20:46 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Converting-Nested-JSON-to-Flat-JSON-using-JOLT/m-p/398976#M250352</guid>
      <dc:creator>Sid17</dc:creator>
      <dc:date>2024-12-17T12:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Nested JSON to Flat JSON using JOLT</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Converting-Nested-JSON-to-Flat-JSON-using-JOLT/m-p/398979#M250353</link>
      <description>&lt;P&gt;Also, FYI I have tried using this JOLT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "getCarListing": {
          "edges": {
            "*": {
              "node": {
                "carClusterIds": {
                  "*": {
                    "element": {
                      "businessRelations": {
                        "*": {
                          "countries": {
                            "*": {
                              "countryCode": "[&amp;amp;6].[&amp;amp;1].CountryCode",
                              "@(2,code)": "[&amp;amp;6].[&amp;amp;1].BR",
                              "@(4,name)": "[&amp;amp;6].[&amp;amp;1].Element"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
 },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "@": "[]"
          }
        }
      }
    }
    }

]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which is giving output in the form:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[ [ "US01", "CZ01", "CA01", "FR01", "DE01" ], [ "SEDAN1000", "SEDAN1000", "SEDAN1000", "TRUCK500", "TRUCK500" ], [ "US", "CZ", "CA", "FR", "DE" ], "CZ01", "SEDAN1000", "SK", [ "MX01", "JP01" ], [ "SUV2020", "COUPE3000" ], [ "MX", "JP" ] ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which is closer to the expected output but need some formatting.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2024 13:55:43 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Converting-Nested-JSON-to-Flat-JSON-using-JOLT/m-p/398979#M250353</guid>
      <dc:creator>Sid17</dc:creator>
      <dc:date>2024-12-17T13:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Nested JSON to Flat JSON using JOLT</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Converting-Nested-JSON-to-Flat-JSON-using-JOLT/m-p/398995#M250360</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/122413"&gt;@Sid17&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;SPAN&gt;Can you try this JOLT&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-SPOILER&gt;[&lt;BR /&gt;{&lt;BR /&gt;"operation": "shift",&lt;BR /&gt;"spec": {&lt;BR /&gt;"data": {&lt;BR /&gt;"getCarListing": {&lt;BR /&gt;"edges": {&lt;BR /&gt;"*": {&lt;BR /&gt;"node": {&lt;BR /&gt;"carClusterIds": {&lt;BR /&gt;"*": {&lt;BR /&gt;"element": {&lt;BR /&gt;"name": "[].element"&lt;BR /&gt;},&lt;BR /&gt;"businessRelations": {&lt;BR /&gt;"*": {&lt;BR /&gt;"countries": {&lt;BR /&gt;"*": {&lt;BR /&gt;"countryCode": "[].businessRelations[].countryCode"&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"operation": "cardinality",&lt;BR /&gt;"spec": {&lt;BR /&gt;"[]": "ONE"&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;]&lt;/LI-SPOILER&gt;&lt;P&gt;Hope it works&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2024 19:53:07 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Converting-Nested-JSON-to-Flat-JSON-using-JOLT/m-p/398995#M250360</guid>
      <dc:creator>Shelton</dc:creator>
      <dc:date>2024-12-17T19:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Nested JSON to Flat JSON using JOLT</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Converting-Nested-JSON-to-Flat-JSON-using-JOLT/m-p/398998#M250362</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/122413"&gt;@Sid17&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;The following spec should do:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "getCarListing": {
          "edges": {
            "*": {
              "node": {
                "carClusterIds": {
                  "*": {
                    "element": "[]"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  ,
  {
    "operation": "shift",
    "spec": {
      "*": {
        "businessRelations": {
          "*": {
            "countries": {
              "*": {
                "countryCode": "[&amp;amp;5].[&amp;amp;3].[&amp;amp;1].CountryCode",
                "@(2,code)": "[&amp;amp;5].[&amp;amp;3].[&amp;amp;1].BR",
                "@(4,name)": "[&amp;amp;5].[&amp;amp;3].[&amp;amp;1].Element"
              }
            }
          }
        }
      }
    }
 },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": "[]"
        }
      }
    }
  }
]&lt;/LI-CODE&gt;&lt;P&gt;The concept is the same as before: You need to group fields at level of the leaf field taking into consideration the parent array and any sub arrays positions for grouping.&lt;/P&gt;&lt;P&gt;The first transformation is used just to simplify the grouping (second transformation ) by removing any parent array where no information is needed but you can have both 1st and 2ed transformation as one if you can count up to the right array\sub-array index.&lt;/P&gt;&lt;P&gt;As I mentioned before, the recommendation for such pattern is to use JSLT transformation as its much simpler to write and require much less lines to achieve the same result.&lt;/P&gt;&lt;P&gt;Also another option that might simplify the spec as well by doing the following:&lt;/P&gt;&lt;P&gt;1- Take advantage of the FlattenJson processor with the following configuration:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_0-1734468371312.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/43118i38103C48699A2953/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_0-1734468371312.png" alt="SAMSAL_0-1734468371312.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This processor will flatten all nested objects as one big object using (.) as separator as configured and will included any arrays as well. The result of this processor after passing the input json will look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
	"data.getCarListing.edges.0.node.id": "1001",
	"data.getCarListing.edges.0.node.identifier": 500001,
	"data.getCarListing.edges.0.node.carClusterIds.0.element.name": "SEDAN1000",
	"data.getCarListing.edges.0.node.carClusterIds.0.element.businessRelations.0.countries.0.countryCode": "US",
	"data.getCarListing.edges.0.node.carClusterIds.0.element.businessRelations.0.code": "US01",
	"data.getCarListing.edges.0.node.carClusterIds.0.element.businessRelations.1.countries.0.countryCode": "CZ",
	"data.getCarListing.edges.0.node.carClusterIds.0.element.businessRelations.1.countries.1.countryCode": "SK",
	"data.getCarListing.edges.0.node.carClusterIds.0.element.businessRelations.1.code": "CZ01",
	"data.getCarListing.edges.0.node.carClusterIds.0.element.businessRelations.2.countries.0.countryCode": "CA",
	"data.getCarListing.edges.0.node.carClusterIds.0.element.businessRelations.2.code": "CA01",
	"data.getCarListing.edges.0.node.carClusterIds.0.metadata.0.name": "clusterId",
	"data.getCarListing.edges.0.node.carClusterIds.0.metadata.0.value": "200011",
	"data.getCarListing.edges.0.node.carClusterIds.1.element.name": "SUV2020",
	"data.getCarListing.edges.0.node.carClusterIds.1.element.businessRelations.0.countries.0.countryCode": "MX",
	"data.getCarListing.edges.0.node.carClusterIds.1.element.businessRelations.0.code": "MX01",
	"data.getCarListing.edges.0.node.carClusterIds.1.metadata.0.name": "clusterId",
	"data.getCarListing.edges.0.node.carClusterIds.1.metadata.0.value": "200012",
	"data.getCarListing.edges.0.node.parentItems.0.identifier": 400050,
	"data.getCarListing.edges.1.node.id": "1002",
	"data.getCarListing.edges.1.node.identifier": 500002,
	"data.getCarListing.edges.1.node.carClusterIds.0.element.name": "TRUCK500",
	"data.getCarListing.edges.1.node.carClusterIds.0.element.businessRelations.0.countries.0.countryCode": "FR",
	"data.getCarListing.edges.1.node.carClusterIds.0.element.businessRelations.0.code": "FR01",
	"data.getCarListing.edges.1.node.carClusterIds.0.element.businessRelations.1.countries.0.countryCode": "DE",
	"data.getCarListing.edges.1.node.carClusterIds.0.element.businessRelations.1.code": "DE01",
	"data.getCarListing.edges.1.node.carClusterIds.0.metadata.0.name": "clusterId",
	"data.getCarListing.edges.1.node.carClusterIds.0.metadata.0.value": "200021",
	"data.getCarListing.edges.1.node.carClusterIds.1.element.name": "COUPE3000",
	"data.getCarListing.edges.1.node.carClusterIds.1.element.businessRelations.0.countries.0.countryCode": "JP",
	"data.getCarListing.edges.1.node.carClusterIds.1.element.businessRelations.0.code": "JP01",
	"data.getCarListing.edges.1.node.carClusterIds.1.metadata.0.name": "clusterId",
	"data.getCarListing.edges.1.node.carClusterIds.1.metadata.0.value": "200022",
	"data.getCarListing.edges.1.node.parentItems.0.identifier": 400051
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then , understanding how you can reference part of the fields in Jolt to get the index will help you group things accordingly to then produce the final result:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "data.getCarListing.edges.*.node.carClusterIds.*.element.businessRelations.*.countries.*.countryCode": {
        "@(1,data\\.getCarListing\\.edges\\.&amp;amp;(0,1)\\.node\\.carClusterIds\\.&amp;amp;(0,2)\\.element\\.businessRelations\\.&amp;amp;(0,3)\\.code)": "&amp;amp;(1,1).&amp;amp;(1,2).&amp;amp;(1,3).&amp;amp;(1,4).BR",
        "@(1,data\\.getCarListing\\.edges\\.&amp;amp;(0,1)\\.node\\.carClusterIds\\.&amp;amp;(0,2)\\.element\\.name)": "&amp;amp;(1,1).&amp;amp;(1,2).&amp;amp;(1,3).&amp;amp;(1,4).Element",
        "@": "&amp;amp;(1,1).&amp;amp;(1,2).&amp;amp;(1,3).&amp;amp;(1,4).countryCode"
      }
    }
  },

  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "*": "[]"
          }
        }
      }
    }
    }
]&lt;/LI-CODE&gt;&lt;P&gt;This will be simpler in the&amp;nbsp; sense that you count horizontally vs vertically to get the index.&lt;/P&gt;&lt;P&gt;Try it out and see how it works. This will help you understand jolt more and give you more options for future transformation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2024 20:56:29 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Converting-Nested-JSON-to-Flat-JSON-using-JOLT/m-p/398998#M250362</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2024-12-17T20:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Nested JSON to Flat JSON using JOLT</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Converting-Nested-JSON-to-Flat-JSON-using-JOLT/m-p/399190#M250438</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;&amp;nbsp;(JOLT expert), The spec you posted worked properly and I'm able to see the flat JSON as expected.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2024 10:39:23 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Converting-Nested-JSON-to-Flat-JSON-using-JOLT/m-p/399190#M250438</guid>
      <dc:creator>Sid17</dc:creator>
      <dc:date>2024-12-20T10:39:23Z</dc:date>
    </item>
  </channel>
</rss>

