Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
Aami
Contributor III
Contributor III

create json array with and without field names

Scenario 1: Create nested json with field names

Expected result;

{
"rootTag": {
"newColumns1": "A",
"newColumn2": "B",
"SUB": [
{
"newColumn3": "C",
"newColumn4": "D",
"SUB2": [
{
"NewCol5": "K",
"NewCol6": "L"
}
]
},
{
"newColumn3": "E",
"newColumn4": "F",
"SUB2": [
{
"NewCol5": "M",
"NewCol6": "N"
}
]
},
{
"newColumn3": "G",
"newColumn4": "H",
"SUB2": [
{
"NewCol5": "O",
"NewCol6": "P"
}
]
},
{
"newColumn3": "X",
"newColumn4": "D",
"SUB2": [
{
"NewCol5": "Q",
"NewCol6": "R"
}
]
},
{
"newColumn3": "Y",
"newColumn4": "D",
"SUB2": [
{
"NewCol5": "S",
"NewCol6": "T"
}
]
}
]
}
}

 

Scenario 2: Created nested json array where the second level should not have field names.
Expected result.

{
"rootTag": {
"newColumns1": "A",
"newColumn2": "B",
"SUB": [{
"newColumn3": "C",
"newCol4": "D",
"SUB2": ["K", "L"]
}, {
"newColumn3": "E",
"newCol4": "F",
"SUB2": ["M", "N"]
}, {
"newColumn3": "G",
"newCol4": "H",
"SUB2": ["O", "P"]
}, {
"newColumn3": "X",
"newCol4": "D",
"SUB2": ["Q", "R"]
}, {
"newColumn3": "Y",
"newCol4": "D",
"SUB2": ["S", "T"]
}]
}
}

Labels (5)
1 Solution

Accepted Solutions
Aami
Contributor III
Contributor III
Author

The sample job structure is as shown below.


0683p000009M8rj.png

 

 

 

In the fixed flow input I am using inline table to populate some sample data.


0683p000009M8qr.png

Lets see the settings from tWriteJsonField. The group by option should be used to to group the values. Here Im considering Col1 & 2 as group by.

0683p000009M8ry.png

 

 

 

 

 

 

 

The above steps are common for both scenario 1 & 2. 

Scenario 1:

The columns 1& 2 are the group by ones and they will have sub elemnets 3 & 4 and 4 will further have sub elements 5 & 6. After adding the first sub element "SUB" add a class attribute and set the fixed value to array. Under the SUB add next sub element as element and set it as loop element. Under this element add another attribute class and set the value to object. Under element add next sub elements (In this case column 3 & 4).

Now the first nest is done. 

For the next one, create another sub element "SUB2" and proceed with the same steps. 

This will give the output with field names.

SUB2": [
{
"NewCol5": "K",
"NewCol6": "L"
}
]

0683p000009M8i5.png

 

Scenario 2:

The columns 1& 2 are the group by ones and they will have sub elemnets 3 & 4 and 4 will further have sub elements 5 & 6. After adding the first sub element "SUB" add a class attribute and set the fixed value to array. Under the SUB add next sub element as element and set it as loop element. Under element add next sub elements (In this case column 3 & 4). 

Do not add the object attribute in this case and skip adding element under the sub for which you dont need the headers(in this case SUB2)

Now the first nest is done. 

For the next one, create another sub element "SUB2" and proceed with the same steps but will skip adding the sub element "element". 

This will give the output without the field names.

"SUB2": ["K", "L"]
0683p000009M8s3.png

 

View solution in original post

1 Reply
Aami
Contributor III
Contributor III
Author

The sample job structure is as shown below.


0683p000009M8rj.png

 

 

 

In the fixed flow input I am using inline table to populate some sample data.


0683p000009M8qr.png

Lets see the settings from tWriteJsonField. The group by option should be used to to group the values. Here Im considering Col1 & 2 as group by.

0683p000009M8ry.png

 

 

 

 

 

 

 

The above steps are common for both scenario 1 & 2. 

Scenario 1:

The columns 1& 2 are the group by ones and they will have sub elemnets 3 & 4 and 4 will further have sub elements 5 & 6. After adding the first sub element "SUB" add a class attribute and set the fixed value to array. Under the SUB add next sub element as element and set it as loop element. Under this element add another attribute class and set the value to object. Under element add next sub elements (In this case column 3 & 4).

Now the first nest is done. 

For the next one, create another sub element "SUB2" and proceed with the same steps. 

This will give the output with field names.

SUB2": [
{
"NewCol5": "K",
"NewCol6": "L"
}
]

0683p000009M8i5.png

 

Scenario 2:

The columns 1& 2 are the group by ones and they will have sub elemnets 3 & 4 and 4 will further have sub elements 5 & 6. After adding the first sub element "SUB" add a class attribute and set the fixed value to array. Under the SUB add next sub element as element and set it as loop element. Under element add next sub elements (In this case column 3 & 4). 

Do not add the object attribute in this case and skip adding element under the sub for which you dont need the headers(in this case SUB2)

Now the first nest is done. 

For the next one, create another sub element "SUB2" and proceed with the same steps but will skip adding the sub element "element". 

This will give the output without the field names.

"SUB2": ["K", "L"]
0683p000009M8s3.png