Read and write
This section contains the code examples for reading from the input data (data.input
) and writing to the output data (data.output
).
Read and write for interim data (data.internal
) is similar.
For more information on how to add a quotation mark "
, backslash \
, line break, or tab to the object in the input data, see If you're not familiar with JSON. For more information about escaping in TSV files, see the Requester's guide.
Basic example
{ "question": "Would you buy an elephant?"
}
{
"type": "view.text",
"label": "Answer the question:",
"content": {
"type": "data.input",
"path": "question"
}
}
Example of writing a response using the field.radio-group component:{
"type": "field.radio-group",
"options": [...],
"data": {
"type": "data.output",
"path": "verdict"
}
}
When you respond with yes and click Send, the result looks like this:
{
"output": {
"verdict": true
}
}
Reading JSON input data
If you pass a JSON object in the input data and want to get a value for some nested key, specify the path to it using the dot as a separator.
{
"name": "Ivan Ivanov",
"registration_address": {
"country": "Russia",
"city": "Moscow",
"address": "Tverskaya str, 3-53"
},
...
{
"type": "data.input",
"path": "registration_address.city"
}
Writing JSON data
The output data is written similarly. If you enter the path separated by dots, the field with the output data will have the object type in the specification.
Reading data with the "array" type
To get a value from a specific element in an array, use the path to specify its sequence number, starting from zero.
{
"images": [
"https://cdn.stocksnap.io/img-thumbs/960w/surfer-wave_3DBOYBPB3X.jpg",
"https://cdn.stocksnap.io/img-thumbs/960w/fisherman-silhouette_UADULRRHEK.jpg",
"https://cdn.stocksnap.io/img-thumbs/960w/old-photo_GEQ27OWZVV.jpg"
]
}
You can reference a specific array element like this:"url": {
"type": "data.input",
"path": "images.<Element number, starting from zero>"
}
If the array length is unknown or very large, you can get all the array values using the helper.transform component.
For example, you can convert an array of image links to an array of view.image components to display them in the interface.
Writing the array data
path
property for the path to the array and the element number starting from zero. Example:{
"type": "data.output",
"path": "images.0"
}