Producing a simple JSON array from a Table

Hello Everyone, I’ve come to seek the guidance of the community. I searched for an answer to this question but I couldn’t find an example that was as simple as my use-case. If there is one, please point me to it!

I need to take data from SmartSheet, modify it and then re-post it to the site. I’m brand new to using REST requests and JSON and honestly I’m a bit over my head. (Also, I should mention that I’m aware of the SmartSheet Reader and Writer nodes but due to the security rules of my organization, I’m not allowed to use them. So I’ve had to make do with the standard Get, Put & Post nodes)

I have a simple JSON array that I’ve tested as a Constant Body in a POST request node and I know that it works. I’ve also made a CSV version of the simple table I’m trying to upload. But I haven’t been able to systematically turn the table into the array. I’ll paste both below.

What I was hoping was that someone could give me a workflow or spell out a workflow that could produce the JSON array below from the CSV in a repeatable fashion, which I could then study and modify as needed.

Any help that any knowledgeable and generous soul in the community could provide would be greatly appreciated! Thank you so much!

[
{
“toBottom”: true,
“cells”: [
{
“columnId”: 7225687444508548,
“value”: “Row 1 Column 1”
},
{
“columnId”: 1596187910295428,
“value”: “Row 1 Column 2”
},
{
“columnId”: 6099787537665924,
“value”: “Row 1 Column 3”
},
{
“columnId”: 3847987723980676,
“value”: “Row 1 Column 4”
},
{
“columnId”: 8351587351351172,
“value”: “Row 1 Column 5”
},
{
“columnId”: 1033237956874116,
“value”: " Row 1 Column 6"
}
]
},
{
“toBottom”: true,
“cells”: [
{
“columnId”: 7225687444508548,
“value”: “Row 2 Column 1”
},
{
“columnId”: 1596187910295428,
“value”: “Row 2 Column 2”
},
{
“columnId”: 6099787537665924,
“value”: “Row 2 Column 3”
},
{
“columnId”: 3847987723980676,
“value”: " Row 2 Column 4"
},
{
“columnId”: 8351587351351172,
“value”: “Row 2 Column 5”
},
{
“columnId”: 1033237956874116,
“value”: " Row 2 Column 6"
}
]
},
{
“toBottom”: true,
“cells”: [
{
“columnId”: 7225687444508548,
“value”: “Row 3 Column 1”
},
{
“columnId”: 1596187910295428,
“value”: “Row 3 Column 2”
},
{
“columnId”: 6099787537665924,
“value”: “Row 3 Column 3”
},
{
“columnId”: 3847987723980676,
“value”: “Row 3 Column 4”
},
{
“columnId”: 8351587351351172,
“value”: “Row 3 Column 5”
},
{
“columnId”: 1033237956874116,
“value”: “Row 3 Column 6”
}
]
},
{
“toBottom”: true,
“cells”: [
{
“columnId”: 7225687444508548,
“value”: “Row 4 Column 1”
},
{
“columnId”: 1596187910295428,
“value”: “Row 4 Column 2”
},
{
“columnId”: 6099787537665924,
“value”: “Row 4 Column 3”
},
{
“columnId”: 3847987723980676,
“value”: " Row 4 Column 4"
},
{
“columnId”: 8351587351351172,
“value”: “Row 4 Column 5”
},
{
“columnId”: 1033237956874116,
“value”: “Row 4 Column 6”
}
]
}
]

Test JSON Array.csv (527 Bytes)

Hey there,

JSON in KNIME is tricky I have to admit - as I just found out :smiley:

In general as a rule of thumb you have to work “from inside out” - so first create the inner-most objects and the combine them to the next layer…

Managed to get it done and it should also work if there are more rows / columns… the last group by node has a list of the structure you need - only thing I did not manage to get done is that toBottom key is before cells key…

Workflow
smartsheetjson.knwf (100.6 KB)

6 Likes

I just tried this out and it worked like a charm! I’ll take the workflow away and try to pick it apart.

Thank you so much! This is extremely helpful and greatly appreciated!

2 Likes

Hi @CKillick

This is an alternative approach. This will ensure that the "toBottom" : true appears at the beginning of the array as per your example in case any other position is being rejected by your target system.

See WF:
Producing a simple JSON array from a Table.knwf (73.7 KB)

As @MartinDDDD mentioned, JSON always brings a nice challange :slight_smile:

4 Likes

I just tried this workflow and it also worked perfectly! I wish I could flag both of the responses as solutions. I think I’m already starting to get a much better idea of how to construct JSON arrays in Knime more generally.

Seriously, thank you both very much!

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.