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.
1 Like
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"
}
}
]
}
2 Likes
Getting around to this!
Where am I adding this code? In Glide?
The stuff above is just a sample of how your output would look like. You have to construct a JavaScript function to produce the JSON string that looks like this:
{
"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"
}
}
]
}
Then, make an API call using it as the body (alongside auth headers).
K.
I do that in a JavaScript column in same sheet as my original JSON right?
Yes that’s correct.
Let me know if I can help you with any other stuff here.
Make sure you use a return function at the end to get the output as a JSON string.
Workflow and production Glide API will costs the same: each row - one update.
Use api V2 instead. 1.add rows to stash. 2. Add rows to table from stash. This way you will have economy
Isn’t workflow consuming more because you need to query out the fields, or does it work differently when you pass in a JSON (i.e it automatically paráes the fields out)?
For API v2, isn’t it only for Glide Big Tables at the moment?
Does query consumes updates? I remember no, so why workflow must consuming more?
Yes, API V2 is for BIG Tables only, for now.
”Costs the same” in my mind is updates costs only.
Yes, for Glide Tables, crafting an API body is the best option if API Call is available.
1 Like
I checked again and you’re right, only the ones with the lightning icon consume updates.
I was thinking the numbers in bubbles here count, but they’re just showing the amount of runs apparently.
2 Likes