<@U04S8PLJWMT> In the builder UI, in the transform...
# ask-ai
a
@kapa.ai In the builder UI, in the transformations section, how to add a field and transform it from an array to a json
k
In the Airbyte Connector Builder UI, the "Add Field" transformation allows you to add new fields to records, and you can use expressions to set the value of the new field. However, based on the available documentation, there is no explicit example or mention of a built-in transformation that directly converts an array to a JSON string or object as part of the "Add Field" transformation. The documentation shows how to add fields with static values, values from the stream slice, or even hashed values from existing fields. For example:
Copy code
yaml transformations:   - type: AddFields     fields:       - path: [ "field1" ]         value: "static_value"       - path: [ "start_date" ]         value: {{ stream_slice['start_date'] }}
Or, to hash a field:
Copy code
yaml transformations:   - type: add     path: from, name     value: {{ record['from']['name'] | hash('md5') }}
[Adding fields (Transformations)](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/record-processing#adding-fields) However, there is no documented filter or function in the transformation syntax that converts an array to a JSON string or object. If you want to add a field whose value is a JSON representation of an array, you would need a function like
to_json
, but the documentation does not mention such a function. Summary: You can add fields and set their values using expressions, but the knowledge sources do not describe a built-in way to transform an array to a JSON string/object within the builder UI transformations. If you need this functionality, you may need to handle it outside of Airbyte or check for future updates to the transformation functions. If you have a specific use case or example, please provide more details, and I can check if there is a workaround or more targeted guidance in the documentation.
a
@kapa.ai I have this API answer [ { "query_parameters": { "usage_point_id_total_count": 3, "page_total_count": 1, "actual_page_number": 1 }, "usage_point_id": [ "50012981971292", "50073082478088", "50047419025123" ] } ] I would like something like this [ { "query_parameters": { "usage_point_id_total_count": 3, "page_total_count": 1, "actual_page_number": 1 }, "usage_point_ids": { { "id", "50012981971292" }, { "id", "50073082478088" }, { "id", "50047419025123" } } } ]
k
A message from kapa.ai
Based on the available Airbyte documentation, the Connector Builder UI's transformation features allow you to add fields, remove fields, and perform some value transformations (such as hashing or referencing other fields). However, there is no documented built-in transformation in the Builder UI that can map an array of strings to an array of objects (i.e., transform
["a", "b"]
into
[{"id": "a"}, {"id": "b"}]
) as you described. The "AddFields" transformation can add static values, values from other fields, or values using simple expressions, but it does not support mapping or iterating over arrays to create new object structures within the transformation syntax. The documentation does not mention a
map
or similar function for this purpose in the Builder UI transformations [[Transformations in Builder UI](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/record-processing#transformations)]. Summary: - You can add new fields and set their values using expressions, but you cannot reshape an array of strings into an array of objects using only the Builder UI transformations. - This type of transformation would require more advanced scripting or a custom connector implementation, which is not supported in the Builder UI as per the current documentation. If you need this transformation, you may need to: - Perform the transformation downstream (in your data warehouse or processing pipeline), or - Develop a custom Python connector where you have full control over record processing. I'm sorry, but the knowledge sources do not contain enough information to provide a solution for this transformation within the Builder UI.
a
@kapa.ai What about with the HTTP Response format "Iterable" ?
Copy code
[
  {
    "record": "{\"query_parameters\":{\"usage_point_id_total_count\":56,\"page_total_count\":1,\"actual_page_number\":1},\"usage_point_id\":[\"50012981971292\",\"50073082478088\",\"50094301420477\",\"50063041459450\",\"50077513194408\",\"50000087467907\",\"50018036942579\",\"50009191128660\",\"50023976542621\",\"50080975478068\",\"50062450783818\",\"50090992376369\",\"50028321372418\",\"50001547822101\",\"50071438924951\",\"50029305895769\",\"50048410855597\",\"24315484641905\",\"50031059353640\",\"50093415443460\",\"50013686824517\",\"50037999209725\",\"50092846287819\",\"24342402125773\",\"24380173484590\",\"24309985365588\",\"24312590288602\",\"24313024446040\",\"24313313881630\",\"24341678564543\",\"24367293621161\",\"50056529760202\",\"50067092738668\",\"50073889191925\",\"50094146282932\",\"24321128635208\",\"24330969417858\",\"24331403571268\",\"24341968000523\",\"24343125732406\",\"24398407942679\",\"24399131526493\",\"50053763369882\",\"50086622740150\",\"50090817393205\",\"50016573167502\",\"50073950784894\",\"50007482819748\",\"50090114559696\",\"50068550059512\",\"50075687398445\",\"50051332313013\",\"50017655516829\",\"50074095502672\",\"30002431708381\",\"50047419025123\"]}"
  }
]
k
A message from kapa.ai
Using the HTTP Response format "Iterable" in Airbyte's Connector Builder UI is intended for API responses where each line is a separate record (i.e., newline-delimited text). When you select the "Iterable" response format, Airbyte wraps each line in a JSON object under a record key, like this:
Copy code
2021-04-14 16:52:18 +00:00   2021-04-14 16:52:23 +00:00
becomes
Copy code
[   { "record": "2021-04-14 16:52:18 +00:00" },   { "record": "2021-04-14 16:52:23 +00:00" } ]
If your API returns a single JSON object per line (as a string), Airbyte will treat each line as a string and place it under the
record
key. For example, if your API response is:
Copy code
{"query_parameters":{...},"usage_point_id":["5001","5002"]} {"query_parameters":{...},"usage_point_id":["5003","5004"]}
Airbyte will output:
Copy code
[   { "record": "{\"query_parameters\":{...},\"usage_point_id\":[\"5001\",\"5002\"]}" },   { "record": "{\"query_parameters\":{...},\"usage_point_id\":[\"5003\",\"5004\"]}" } ]
However, Airbyte does not automatically parse the stringified JSON inside the
record
field back into a JSON object.
The documentation does not mention a built-in way to further transform or parse this string into a structured object or to reshape arrays within the Builder UI using the "Iterable" format [[Iterable Response Format](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/record-processing#iterable)]. Summary: - The "Iterable" response format will wrap each line as a string under the
record
key. - It will not automatically parse or restructure the JSON string inside the
record
field. - There is no documented way in the Builder UI to transform an array of strings into an array of objects within the "Iterable" format or to parse the stringified JSON into a structured object. If you need to further process the data (e.g., parse the stringified JSON or reshape arrays), you would need to do this outside of Airbyte or with a custom connector, as the Builder UI does not support this transformation natively according to the current documentation [[Iterable Response Format](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/record-processing#iterable)].
a
@kapa.ai I want to use the array list as a parent stream, how to do it ?
k
A message from kapa.ai
To use an array list as a parent stream in Airbyte's Connector Builder UI, you need to configure the parent stream so that each element of the array becomes a partition for the child stream. Here’s how you can do it, based on the documentation: 1. Set up the Parent Stream: - In your parent stream configuration, use the Field Path (or record selector) to point directly to the array you want to use. For example, if your API response is:
Copy code
json      {        "usage_point_id": [          "50012981971292",          "50073082478088",          "50047419025123"        ]      }
Set the field path to
usage_point_id
. This will treat each element in the array as a separate record in the parent stream [[Field Path](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/record-processing#field-path)]. 2. Configure the Child Stream to Use the Parent Stream: - In the child stream, select the parent stream you just configured. - Set the Parent Key to the value in the array (for example, the string itself if each array element is an ID). - Set the Current Parent Key Value Identifier (e.g.,
usage_point_id
)—this is the variable you’ll use in the child stream’s URL or parameters, like
{{ stream_partition.usage_point_id }}
. 3. Reference the Partition Value in the Child Stream: - In the child stream’s configuration (such as the URL path or request parameters), use the identifier you set above to reference the current partition value. For example:
Copy code
/endpoint/{{ stream_partition.usage_point_id }}
Example Flow: - Parent stream extracts each
usage_point_id
as a record. - Child stream uses each
usage_point_id
as a partition to fetch related data. Important Note: If your array is nested inside another object, set the field path accordingly (e.g.,
["data", "usage_point_id"]
). If your API response is a root-level array, you can omit the field path [[Field Path](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/record-processing#field-path)]. Limitation: If your parent stream returns a single record with an array field (not an array of objects), you must use the field path to extract the array as the list of records. Airbyte does not natively support mapping an array of strings to an array of objects in the Builder UI, but using the field path as described will allow you to use each array element as a partition [[Parent Stream](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/partitioning#parent-stream)]. If you need to further reshape the array (e.g., wrap each string in an object), this is not currently supported in the Builder UI according to the documentation. --- References: - [Parent Stream Partitioning](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/partitioning#parent-stream) - [Field Path for Record Selection](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/record-processing#field-path)
a
@kapa.ai I have this error in the field path : Something went wrong in the connector. See the logs for more details. dictionary update sequence element #0 has length 14; 2 is required
Copy code
Traceback (most recent call last):
  File "/home/airbyte/.pyenv/versions/3.10.15/lib/python3.10/site-packages/airbyte_cdk/sources/abstract_source.py", line 152, in read
    yield from self._read_stream(
  File "/home/airbyte/.pyenv/versions/3.10.15/lib/python3.10/site-packages/airbyte_cdk/sources/abstract_source.py", line 276, in _read_stream
    for record_data_or_message in record_iterator:
  File "/home/airbyte/.pyenv/versions/3.10.15/lib/python3.10/site-packages/airbyte_cdk/sources/streams/core.py", line 196, in read
    for record_data_or_message in records:
  File "/home/airbyte/.pyenv/versions/3.10.15/lib/python3.10/site-packages/airbyte_cdk/sources/declarative/declarative_stream.py", line 154, in read_records
    yield from self.retriever.read_records(self.get_json_schema(), stream_slice)  # type: ignore # records are of the correct type
  File "/home/airbyte/.pyenv/versions/3.10.15/lib/python3.10/site-packages/airbyte_cdk/sources/declarative/retrievers/simple_retriever.py", line 446, in read_records
    for stream_data in self._read_pages(record_generator, self.state, _slice):
  File "/home/airbyte/.pyenv/versions/3.10.15/lib/python3.10/site-packages/airbyte_cdk/sources/declarative/retrievers/simple_retriever.py", line 347, in _read_pages
    for record in records_generator_fn(response):
  File "/home/airbyte/.pyenv/versions/3.10.15/lib/python3.10/site-packages/airbyte_cdk/sources/declarative/retrievers/simple_retriever.py", line 532, in _parse_records
    yield from self._parse_response(
  File "/home/airbyte/.pyenv/versions/3.10.15/lib/python3.10/site-packages/airbyte_cdk/sources/declarative/retrievers/simple_retriever.py", line 258, in _parse_response
    yield from self.record_selector.select_records(
  File "/home/airbyte/.pyenv/versions/3.10.15/lib/python3.10/site-packages/airbyte_cdk/sources/declarative/extractors/record_selector.py", line 88, in select_records
    yield from self.filter_and_transform(
  File "/home/airbyte/.pyenv/versions/3.10.15/lib/python3.10/site-packages/airbyte_cdk/sources/declarative/extractors/record_selector.py", line 119, in filter_and_transform
    for data in normalized_data:
  File "/home/airbyte/.pyenv/versions/3.10.15/lib/python3.10/site-packages/airbyte_cdk/sources/declarative/extractors/record_selector.py", line 128, in _normalize_by_schema
    normalized_record = dict(record)
ValueError: dictionary update sequence element #0 has length 14; 2 is required
I put * to get all element
k
A message from kapa.ai
The error you are seeing:
Copy code
ValueError: dictionary update sequence element #0 has length 14; 2 is required
typically occurs when Airbyte tries to convert a list of strings into a dictionary, but the elements are not key-value pairs (tuples of length 2), which is what Python's
dict()
expects. Why this happens in your case: You mentioned your API response looks like this:
Copy code
json {   "usage_point_id": [     "50012981971292",     "50073082478088",     "50047419025123"   ] }
If you set the field path to
["usage_point_id", "*"]
, Airbyte will extract each string (e.g.,
"50012981971292"
) as a record. However, Airbyte expects each record to be a dictionary/object, not a string. When it tries to convert the string to a dictionary, it fails, resulting in the error you see. What the documentation says: - The field path with
*
is used to iterate over arrays, but the extracted value at each step must be an object/dictionary, not a primitive value like a string or number [[Field Path](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/record-processing#field-path)]. - There is no built-in way in the Builder UI to wrap each string in an object (e.g.,
{ "id": "50012981971292" }
) before it is output as a record [[Field Path](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/record-processing#field-path)]. How to resolve: - If possible, modify the API or use a different endpoint that returns an array of objects instead of an array of strings. - If you cannot change the API, you cannot use this array directly as a parent stream in the Builder UI, because Airbyte expects each record to be an object. There is no documented way to transform an array of strings into an array of objects in the Builder UI. Summary: The error occurs because Airbyte expects each record to be a dictionary/object, but your field path extracts strings. The knowledge sources do not provide a way to wrap these strings as objects in the Builder UI. You may need to handle this transformation outside of Airbyte or with a custom connector. If you have control over the API, return an array of objects like:
Copy code
json "usage_point_id": [   { "id": "50012981971292" },   { "id": "50073082478088" },   { "id": "50047419025123" } ]
Otherwise, this transformation is not supported in the Builder UI according to the current documentation.
a
@kapa.ai Is it possible to set a parametrized request with the parent stream value ?
k
A message from kapa.ai
Yes, it is possible to set a parameterized request using the parent stream value in Airbyte's Connector Builder UI. When configuring a child stream, you can use the value from the parent stream as a parameter in your requests. This is achieved by referencing the parent key value using the
{{ stream_partition.<identifier> }}
syntax in the URL path, query parameters, or headers. The "Current Parent Key Value Identifier" you set in the parent stream configuration determines the variable name you use for interpolation. For example, if your parent stream provides an
id
and you set the identifier to
order
, you can use
/orders/{{ stream_partition.order }}/notes
as the URL path in your child stream. This will inject the parent stream's value into the request for each partition [[Parent Stream](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/partitioning#parent-stream)]. You can also use this value in query parameters or headers, depending on your API's requirements. If you need more complex injection logic (such as adding a prefix, combining values, or conditional logic), you can disable the default injection and use the generic parameter section with Jinja expressions referencing
stream_partition
variables [[Custom parameter injection](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/partitioning#custom-parameter-injection)]. In summary: You can set up parameterized requests using parent stream values by referencing them with
{{ stream_partition.<identifier> }}
in your request configuration.
a
@kapa.ai The parametrized request does not work when I put more than one value : - type: ListPartitionRouter values: - '24380173484590' - '24380173484590' cursor_field: prm request_option: type: RequestOption inject_into: request_parameter field_name: usage_point_id
k
A message from kapa.ai
Based on the available Airbyte documentation, the ListPartitionRouter is designed to iterate over a list of values and inject each value into outgoing API requests as specified by the
request_option
. Your configuration is valid for specifying multiple values, even if they are duplicates:
Copy code
yaml - type: ListPartitionRouter   values:     - '24380173484590'     - '24380173484590'   cursor_field: prm   request_option:     type: RequestOption     inject_into: request_parameter     field_name: usage_point_id
Expected Behavior: This should result in two requests, each with
usage_point_id=24380173484590
as a request parameter. The documentation does not mention any restriction or special handling for duplicate values in the
values
array—each value should be used in a separate request cycle [[ListPartitionRouter Reference](https://docs.airbyte.com/platform/connector-development/config-based/understanding-the-yaml-file/partition-router)]. If it does not work as expected: - The knowledge sources do not describe any built-in deduplication or error for repeated values in the
values
list. - If you are experiencing issues (such as only one request being made or an error), this is not documented behavior, and the knowledge sources do not provide troubleshooting steps for this specific scenario. Summary: According to the documentation, using more than one value (even if they are the same) in the
values
list of a ListPartitionRouter should work and result in multiple requests. If it does not, the knowledge sources do not contain enough information to explain or resolve this issue. You may need to check the connector logs for more details or consult Airbyte community support for further troubleshooting [[ListPartitionRouter Reference](https://docs.airbyte.com/platform/connector-development/config-based/understanding-the-yaml-file/partition-router)].
a
@kapa.ai is it possible to change the jinja environment used by Airbyte ?
k
A message from kapa.ai
I'm sorry, but the knowledge sources do not contain any information about changing the Jinja environment used by Airbyte. There is no documentation or reference indicating that the Jinja environment can be customized or replaced within Airbyte's configuration or connector development process. If you need this functionality, you may need to consult Airbyte's community or consider a custom implementation outside the documented features.