How can I use input.config to get object not just an item from the object
I have an object that I output from another script using the Output.Set(key: value) method. The value that I’m passing is an array of json objects. It seems that there are a lot of objects to transform the object but I would prefer to just pass the object to my script to iterate over the object and use dot notation to get the values that I would like.
I don’t see anything that just lets me keep the object as is and pass it through input.config only transforms or operations like length? Is there no way to pass an array or object??
Page 1 / 1
Sorry, I don’t know JavaScripting, so hopefully someone else will be able to help you below. We have lots of JavaScript experts in the community, so someone should chime in very soon.
In the meantime, while you’re waiting for a response from someone else, if you’re interested in a no-code way of iterating through arrays or JSON objects that doesn’t require JavaScript at all, I personally use Make’s iteration tool for this.
This is a great question because it’s a wonderful opportunity to discuss the concept of serialization with coding learners!
In this scenario, what we have to do is serialize the array (to turn it into a datatype that is recognized by Airtable) and then deserialize it to turn it back into an array you would normally operate with.
In the first script, that’s where we serialize it using the function `JSON.stringify`:
Now, in the second script you would deserialize it, using the function `JSON.parse`. Then, use it like any other array of objects:
const { serializedArray } = input.config()
const arrayOfObj = JSON.parse(serializedArray)
for (const obj of arrayOfObj) { console.log(obj.key1) console.log(obj.key2) }
Don’t forget to add `serializedArray` as a variable to input.config:
If you have any questions about this, let us know!
Airtable automation scripts only support strings, numbers, booleans, and arrays of strings or numbers via input.config(). You cannot pass complex objects or arrays of objects directly.
As suggested by @BuildForAT, you’ll need to serialize your object into a string before passing it, and then deserialize it when you want to use it.