I’m hoping to get the latest and greatest solution to a common challenge:
Turning a JSON array into rows in a separate table.
Here’s one of the simplest looking solutions I found.
Wondering if there are any others?
I want to get a list of services for a client from a data source and then add them to a services_list table in Glide (separate to the table where I store the json).
Purpose is to allow user to select services associated with that client from a choice component. So I need to add rows for many clients to same table over time and will use a unique id for each client so I can filter them for my choice component.
All help appreciated 
1 Like
A not-very-cost-effective way imo is sending them to a webhook workflow, loop through the JSON, parse each field out using query JSON and finally add a row.
A better way but more complex is using either JSONata or JavaScript to turn your JSON into something that fits with the Glide API, and then send an API call to batch add multiple rows to the destination table.
So:
- Get JSON and store in column
- Transform JSON (into ?? format)
- Use Glide API to add each record in the array to rows in a glide table I specify
If that is correct, are you able to elaborate on steps 2, 3 please?
If your JSON is already valid, step 2 would require JSONata or JavaScript (I usually do JavaScript) to turn each element in your JSON array to a format that’s fitting for adding a row in Glide.
Sample mutation in Glide:
{
"kind": "add-row-to-table",
"tableName": "your table's name here",
"columnValues": {
"columnID1": "value1",
"columnID2": "value2"
}
}
A JavaScript function would convert your raw data into this format, and then you will send an API call to add the rows, with the mutations array in the body of the API call.
{
"appID": "appID here",
"mutations": [
{
"kind": "add-row-to-table",
"tableName": "your table's name here",
"columnValues": {
"columnID1": "value1",
"columnID2": "value2"
}
},
{
"kind": "add-row-to-table",
"tableName": "your table's name here",
"columnValues": {
"columnID1": "value3",
"columnID2": "value4"
}
}
]
}