I am using Quickbase Pipelines to pull data from a REST API and save it into a table. The flow of the pipeline is:
B. Fetch JSON
C. Prepare Bulk Record Upsert
D. Iterate over JSON records
For each JSON Handler - JSON Objects (D) Do
E. Add Bulk Upsert Row
F. Commit Upsert
In the "Add a Bulk Upsert Row" step I am mapping fields from my table to properties of incoming JSON records.
I am facing a challenge around "custom fields" in my JSON records. There are fields where instead of simply appearing as "key": "value"
pairs in JSON, they appear in a nested array similar to this:
"custom_fields": [
{
"key": "street",
"value": "foo",
},
{
"key": "city",
"value": "bar",
},
{
"key": "state",
"value": "baz",
}
]
I've been able to extract specific values by their key from this structure using this Jinja code block inside my upsert step:
{% for field in d.custom_fields %}
{% if field['key'] == 'street' %}
{{ field['value'] }}
{% endif %}
{% endfor %}
This works well for Text-type fields but this technique fails when trying to get a JSON array value into a Multi-Select Text-type field.
When I use the a Jinja code block like the one above to parse this bit of JSON:
"custom_fields": [
{
"key": "choices",
"value": [
"foo",
"bar",
"baz"
],
}
]
I get these 3 values in my Multi-Select Text field: [u'foo'
, u'bar'
and u'baz']
.
It's as if Quickbase / Jinja are parsing the value from JSON as a literal string rather than an array.
My question is - How can I get the above JSON value to be transformed into the correct choices: foo
, bar
and baz
?
Update: Having examined the activity logs for the pipeline, I've found that the JSON Object that QB derived from the actual JSON has the value as "[u'foo', u'bar', u'baz']"
- a string - which explains the odd values ending up in the table field. Might this be a bug?
I've also found that the same JSON Object has a copy of itself under the property raw_record
and in that copy the value is a sensible ['foo', 'bar', 'baz']
. I've not been able, however, to make use of the raw_record
in my Jinja templates.