| Column | Property | Type | Alias |
|---|---|---|---|
| JSON-INPUT | name | VARCHAR | Name |
| JSON-INPUT | png | VARCHAR | Flag |
| JSON-INPUT | alt | VARCHAR | Alt_Text |
JSON-INPUT in this example is the name of the column in our input that contains the raw JSON data.
When we sample the data from the transformation, we will see something like the following table:
| Name | Flag | Alt_Text |
|---|---|---|
| Cyprus | https://flagcdn.com/w320/cy.png | The flag of Cyprus. |
| Somalia | https://flagcdn.com/w320/so.png | The flag of Somalia. |
| Venezuela | https://flagcdn.com/w320/ve.png | The flag of Venezuela. |
For an alternative method of extracting semi-structured data, you can use the Extract Nested Data component.
Use case
The Flatten Variant component is used to flatten and extract fields from semi-structured data in JSON format. Some common uses for this include:- Taking data from an API that returns a nested JSON object, and putting it into the columns and rows of a table to allow further transformations.
- Extracting nested data from sources like S3 logs, CloudTrail, or Kafka, making the data ready for analysis.
- Preparing semi-structured JSON data for loading into relational tables without losing granularity.
Properties
A human-readable name for the component.
Choose whether to include input columns in the output table.
Specify each item in the source array that will be mapped to a column in the target table. For each item, complete the following fields in the Column Mapping dialog.
- Column: Select the column in the source table that contains the raw semi-structured data.
- Property: The name of the element within the semi-structured data that you want to map to an output column.
- Type: The data type of the output column you are mapping the element to.
- Alias: The name of the output column you are mapping the element to.
If an element of the source data contains a nested array, the Column Flattens property will allow you to extract the nested array’s elements into individual elements that can then be mapped to columns in the Column Mapping property. For each nested element you want to extract, complete the following fields in the Column Flattens dialog.To address the
- Column: Select the column in the source table that contains the raw semi-structured data.
- Property: The name of the element within the nested array that you want to map to a column.
- Alias: The name of the column you are mapping the element to. The alias you create here can then be selected in the Column drop-down of the Column Mapping dialog.
- Outer: Determines how to handle input rows that can’t be expanded (for example, because they have no fields to expand, or because they can’t be accessed by the name you gave as the Property). Select No to completely omit these rows from the output, or Yes to generate an output row with
NULLvalues. - Recursive: Select No if only the input element referenced by the Property field is to be expanded. Select Yes for the expansion to be performed on all sub-elements recursively.
- Mode: Select whether the expansion should be performed on only Object elements, only Array elements, or Both types of element.
alt element of this data, you need to enter country.flags.alt in the Property field. Dot notation allows you to reach any level of nesting in the structure.You can use Grid Variables in this dialog if desired.
