pass
The pass transformer does not directly transform a value, but passes a specific child of the data to a new cursor.
This is also the default transformer if a name is not specified in the schema.
Configuration
Key |
Type |
Required |
Value |
---|---|---|---|
|
string |
Yes |
Key of the child object to pass |
|
Yes |
Cursor to pass the child object to |
Example
The code below passes the root data object to the pass transformer, which then passes only the “firefighters” list to the list-to-object transformer.
This leaves all the other key values untouched, while replacing the “firefighters” list with just a single value.
from json import dumps
from recompose import CursorSchema, transform
data = {
"chefs": [
{
"name": "Alice"
},
{
"name": "Bob"
}
],
"firefighters": [
{
"name": "Daniel"
},
{
"name": "Esther"
}
],
"zookeepers": [
{
"name": "Gregory"
},
{
"name": "Harold"
}
]
}
schema: CursorSchema = {
"version": 1,
"perform": {
"transform": "pass",
"path": "firefighters",
"cursor": {
"perform": "list-to-object",
}
}
}
transformed = transform(schema, data)
print(dumps(transformed, indent=4))
Result
{
"chefs": [
{
"name": "Alice"
},
{
"name": "Bob"
}
],
"firefighters": {
"name": "Daniel"
},
"zookeepers": [
{
"name": "Gregory"
},
{
"name": "Harold"
}
]
}