Dear callin.io Community,
I'm looking to "flatten" this collection, and I know it's possible with arrays. I was wondering if there's a workaround to achieve the same with collections.
I have an Airtable API Call that outputs the following data structure:
In the next step, I'm transforming this into JSON using the following formula:
{{map(records; “fields”)}}
This results in my JSON not including the "id" or "createdTime".
What can I do to either bring these a level down into the fields collection or include them all in my JSON string?
Thanks in advance!
Welcome to the callin.io community!
Please provide the output bundles of the above modules by running the scenario (or get from the scenario History tab), then click the white speech bubble on the top-right of each module and select “Download input/output bundles”.
A.
Save each bundle contents in your text editor as a bundle.txt
file, and upload it here into this discussion thread.
Uploading them here will look like this:
module-1-input-bundle.txt (12.3 KB)
module-1-output-bundle.txt (12.3 KB)
B.
If you are unable to upload files on this forum, alternatively you can paste the formatted bundles in this manner:
-
Either add three backticks
```
before and after the code, like this:```
input/output bundle content goes here
``` -
Or use the format code button in the editor:
Providing the input/output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.
This will allow others to better assist you. Thanks!
blueprint (10).json (5.9 KB)
Here you go, thanks in advance!
Here's the JSON output I'm aiming for after transforming my data. I need to exclude the fields
array from my blueprint.
[ { "body": { "records": [ { "id": "recrsBYQ", "createdTime": "2024-09-06T10:22:21.000Z", "fields1": "xyz", "fields2": true }, { "id": "rec123XYZ", "createdTime": "2024-09-07T12:00:00.000Z", "fields1": "abc", "fields2": false } ] } } ]
[ { "json": "[{{"id":"recrsBYQ","createdTime":"2024-09-06T10:22:21.000Z","fields1":"xyz","fields2":true}},{{"id":"rec123XYZ","createdTime":"2024-09-07T12:00:00.000Z","fields1":"abc","fields2":false}}]" } ]
Welcome to the callin.io community!
You can use a Text Parser “Replace” module with this Pattern (regular expression):
"fields":s+{(?<fields>[wW]+?)}
Proof
Important Info
Global match must be set to YES!
Screenshot
Output
For more information, see Text Parser in the callin.io Help Center:
Match Pattern
The Match pattern module enables you to find and extract string elements matching a search pattern from a given text. The search pattern is a regular expression (aka regex or regexp), which is a sequence of characters in which each character is either a metacharacter, having a special meaning, or a regular character that has a literal meaning.
- The complete list of metacharacters can be found on the MDN web docs website.
- For a tutorial on how to create regular expressions, we recommend the RegexOne website.
- For an easy, quick regex generator, try the Regular Expressions generator.
- For experimenting with regular expressions, we recommend the regular expressions 101 website. Just make sure to tick the ECMAScript (JavaScript) FLAVOR in the left panel.
Hope this helps!
You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.
-
Copy the code below by clicking the copy button when you mouseover the top-right of the code block
-
Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV to paste in the canvas.
-
Click on each imported module and save it. You may need to remap some variables.
Modules JSON Export
{
"subflows": [
{
"flow": [
{
"id": 5,
"module": "regexp:Replace",
"version": 1,
"parameters": {},
"mapper": {
"pattern": ""fields":s+{(?<fields>[wW]+?)}",
"value": "$1",
"global": true,
"sensitive": true,
"multiline": false,
"singleline": false,
"text": "{n "body": {n "records": [n {n "id": "recrsBYQ",n "createdTime": "2024-09-06T10:22:21.000Z",n "fields": {n "fields1": "xyz",n "fields2": truen }n },n {n "id": "rec123XYZ",n "createdTime": "2024-09-07T12:00:00.000Z",n "fields": {n "fields1": "abc",n "fields2": falsen }n }n ]n }n}n"
},
"metadata": {
"designer": {
"x": -21,
"y": 398,
"messages": [
{
"category": "last",
"severity": "warning",
"message": "A transformer should not be the last module in the route."
}
]
},
"restore": {
"expect": {
"global": {
"mode": "chose"
},
"sensitive": {
"mode": "chose"
},
"multiline": {
"mode": "chose"
},
"singleline": {
"mode": "chose"
}
}
},
"expect": [
{
"name": "pattern",
"type": "text",
"label": "Pattern",
"required": true
},
{
"name": "value",
"type": "text",
"label": "New value"
},
{
"name": "global",
"type": "boolean",
"label": "Global match",
"required": true
},
{
"name": "sensitive",
"type": "boolean",
"label": "Case sensitive",
"required": true
},
{
"name": "multiline",
"type": "boolean",
"label": "Multiline",
"required": true
},
{
"name": "singleline",
"type": "boolean",
"label": "Singleline",
"required": true
},
{
"name": "text",
"type": "text",
"label": "Text"
}
]
}
}
]
}
],
"metadata": {
"version": 1
}
}
Thanks for the follow-up.
-
You mentioned "Match pattern," but the module you're utilizing is "Replace." Could you clarify which one is accurate?
-
As I need to make an API call beforehand to retrieve the data, the body is a collection. Your replace module doesn't support collections because it requires text input. Would you mind trying again with a "Parse JSON" module first to ensure it's simulated correctly?
Thanks a lot!
-
Replace, corrected.
2.
You can disable “Parse Response” within the HTTP module to receive the JSON output instead.
It appears the issue isn't with the http module, but rather with the Airtable API call module.
Is there an alternative solution for this?
Additionally, the Transform JSON module is not functioning correctly with the output from the regex module.
Transform JSON input
{{map(15.text; "records")}}
Error Message
DataError
Failed to map 'object': Function 'map' finished with error! Invalid array.
I've done a bit more testing and realized I need the id
and createdTime
parameters within the fields array. This will allow me to map them correctly and obtain an array for use with my transform to JSON module.
Is there a way to include these parameters in an array?
In that scenario, you can simply apply the “Transform to JSON” module to the body first.
And the regex requires a minor adjustment:
"fields":{(?<fields>[wW]+?)}