Flattening Nested JSON Data using Key Value Pivot with KingswaySoft

19 December 2025
KingswaySoft Team
Integrating data from modern REST APIs often presents a familiar challenge: handling nested JSON structures that need to be flattened into tabular datasets for reporting. This scenario is especially common when working with survey, feedback, or form-based systems, where a single response contains a parent record (the respondent) and multiple layers of child information (questions and answers).

For example, consider a Survey API that returns data in the following format:

{
  "responses": [
    {
      "id": "R1",
      "submittedOn": "2025-10-01T14:25:00Z",
      "respondent": {
        "id": "S1",
        "name": "John Smith"
      },
      "questions": [
        { "id": "Q1", "type": "satisfaction", "answer": "Very satisfied" },
        { "id": "Q2", "type": "recommendation", "answer": "Yes" },
        { "id": "Q3", "type": "comments", "answer": "Excellent service!" }
      ]
    },
    {
      "id": "R2",
      "submittedOn": "2025-10-02T11:05:00Z",
      "respondent": {
        "id": "S2",
        "name": "Jane Doe"
      },
      "questions": [
        { "id": "Q1", "type": "satisfaction", "answer": "Neutral" },
        { "id": "Q2", "type": "recommendation", "answer": "Maybe" },
        { "id": "Q3", "type": "comments", "answer": "Could be faster." }
      ]
    },
    {
      "id": "R3",
      "submittedOn": "2025-10-03T09:10:00Z",
      "respondent": {
        "id": "S3",
        "name": "Carlos Mendes"
      },
      "questions": [
        { "id": "Q1", "type": "satisfaction", "answer": "Very satisfied" },
        { "id": "Q2", "type": "recommendation", "answer": "Yes" },
        { "id": "Q3", "type": "comments", "answer": "Great experience!" }
      ]
    }
  ]
}


In this structure, each client object contains metadata (like id, name, and submittedOn) and an array of survey questions. To prepare this data for analysis, we need to flatten it into a tabular form where each question’s answer becomes a separate column, resulting in a single row per respondent.
 
The desired output should look like this:

Customer survey data table showing satisfaction levels and recommendations.

Why Not Just Use a Simple Merge Join?

At first glance, it might seem straightforward to flatten the arrays and join them back to the parent using a standard Merge Join. However, because each parent has multiple related survey answers, this approach creates a one-to-many relationship. The result is multiple rows per parent record, rather than the single, wide record required for analysis.

Data integration workflow showing JSON source, sort, merge join, and dummy destination with example output data.

This duplication makes it difficult to produce a unique record per client. To address this, some may turn to complex Lookup patterns.

Traditional Approach: Using Multiple Outputs and Premium Lookups

In traditional ETL design, flattening this specific type of nested JSON requires splitting the child data into separate streams based on the question type and then re-joining them.

This design usually involves a Conditional Split transformation to separate the question output into three streams (e.g., “comments”, “recommendations”, and “satisfaction”).

Data flow diagram showing Conditional Split to Premium Lookups for comments, recommendation, and satisfaction.

You would then configure the split conditions based on the specific type or ID of the question:

Conditional Split Transformation Editor in SSIS showing condition configuration for comments and recommendations.

Once the streams are split, you must reconnect them to the parent data. This requires multiple Premium Lookup components to align the child data back with the corresponding parent entities.

Data flow diagram showing JSON source, conditional split, and premium lookups leading to a dummy destination.

For each Premium Lookup, you must explicitly map the parent keys to ensure the answers align with the correct client record.

KingswaySoft Premium Lookup Component Editor showing data type mapping and match type configuration.

Then, you need to configure the output columns. You may manually rename the output alias for every lookup (for example, renaming answer to comments) to ensure they map correctly in the destination.


Premium Lookup Component Editor showing output column configuration for matched rows.

You would then repeat this process for the next stream, configuring a separate lookup and renaming that column to recommendations.


KingswaySoft Premium Lookup Component Editor showing column configurations and data types for input and lookup tables.

While this method works, the final output requires significant effort to build. In addition, this approach scales poorly. Each additional question type requires another condition in the Conditional Split and an entirely new Premium Lookup component. As the survey grows, the data flow becomes brittle and difficult to maintain.

A Simpler Way: Using Key Value Pivot in JSON Source

KingswaySoft’s JSON Source component offers a much cleaner solution through the Key Value Pivot feature within the Document Designer. By pivoting key/value pairs directly within the source, you can flatten nested structures without a single Lookup or Conditional Split. This reduces the component count, improves performance, and makes the package significantly easier to read.

Here is how to configure it.

Step 1: Configure the Child Array

Navigate to the Document Designer page in your JSON Source component. Locate the questions array node. Set the Output Type to Key Value Pivot. Select the identifier you would like to use as the Key (in this case, id).

KingswaySoft JSON Source Editor showing JSON data structure for data extraction.

Step 2: Define Expected Keys

Next, double-click the Output Settings cell next to Key Value Pivot to open the Key Value Pivot Editor.

Under Expected Keys, enter the static values you expect from the API (such as Q1, Q2, Q3). For each key, you can assign a friendly Column Name, such as satisfaction, recommendations, or comments.

Note: You can ignore the type values in the mapping if they are not required for the final output.


Key Value Pivot Editor showing expected keys Q1, Q2, Q3 and columns with data type DT_WSTR-nvarchar.

Step 3: Finalize Columns

Once configured, head to the Columns page. You can now uncheck the generic type fields since we have mapped the specific values to their own named columns.


KingswaySoft JSON Source Editor showing data source configuration for clients with columns like _RowIndex, comments, and submittedOn.

Conclusion

Once configured, the JSON Source automatically produces a flattened dataset with each question answer as its own column, all within a single component.


Data pipeline showing JSON source, dummy destination, and data viewer with client data: rows, IDs, dates, names, satisfaction, recommendations, comments.

The Key Value Pivot feature transforms what used to be a complex, multi-component design pattern into a simple configuration task. By pivoting data at the source, you improve readability and streamline the process of working with complex, nested API outputs.

Archive

December 2025 2 November 2025 2 October 2025 2 September 2025 2 August 2025 2 July 2025 2 June 2025 1 May 2025 2 April 2025 3 March 2025 1 February 2025 1 January 2025 2 December 2024 1 November 2024 3 October 2024 1 September 2024 1 August 2024 2 July 2024 1 June 2024 1 May 2024 1 April 2024 2 March 2024 2 February 2024 2 January 2024 2 December 2023 1 November 2023 1 October 2023 2 August 2023 1 July 2023 2 June 2023 1 May 2023 2 April 2023 1 March 2023 1 February 2023 1 January 2023 2 December 2022 1 November 2022 2 October 2022 2 September 2022 2 August 2022 2 July 2022 3 June 2022 2 May 2022 2 April 2022 3 March 2022 2 February 2022 1 January 2022 2 December 2021 1 October 2021 1 September 2021 2 August 2021 2 July 2021 2 June 2021 1 May 2021 1 April 2021 2 March 2021 2 February 2021 2 January 2021 2 December 2020 2 November 2020 4 October 2020 1 September 2020 3 August 2020 2 July 2020 1 June 2020 2 May 2020 1 April 2020 1 March 2020 1 February 2020 1 January 2020 1 December 2019 1 November 2019 1 October 2019 1 May 2019 1 February 2019 1 December 2018 2 November 2018 1 October 2018 4 September 2018 1 August 2018 1 July 2018 1 June 2018 3 April 2018 3 March 2018 3 February 2018 3 January 2018 2 December 2017 1 April 2017 1 March 2017 7 December 2016 1 November 2016 2 October 2016 1 September 2016 4 August 2016 1 June 2016 1 May 2016 3 April 2016 1 August 2015 1 April 2015 10 August 2014 1 July 2014 1 June 2014 2 May 2014 2 February 2014 1 January 2014 2 October 2013 1 September 2013 2 August 2013 2 June 2013 5 May 2013 2 March 2013 1 February 2013 1 January 2013 1 December 2012 2 November 2012 2 September 2012 2 July 2012 1 May 2012 3 April 2012 2 March 2012 2 January 2012 1

Tags