Working with JSON Data in RoboTask Variables
Posted: Fri Apr 03, 2026 10:35 am
Many RoboTask actions return data in JSON (JavaScript Object Notation) format. To process this information effectively, you need to know how to address specific fields or elements within a variable containing a JSON string.
RoboTask supports two primary methods for addressing JSON fields. Let’s look at them using a variable named SomeData containing the following structure:
Method 1: Dot Notation (Classical)
The most intuitive way to access data is by using a "dot" to separate levels of the hierarchy.
Cons: This method will fail if a field name contains special characters like spaces or dots (e.g., "User Name" or "item.id"), which are technically valid in JSON.
Method 2: Bracket Notation (Python-style)
To handle complex field names or to ensure maximum compatibility, you can use square brackets and quotes. This is the preferred method when dealing with REST APIs that might return "unfriendly" key names.
Why use Bracket Notation?
In modern web services, you might encounter JSON keys like this: { "Service Status": "OK", "v1.0.attribute": "value" }
RoboTask supports two primary methods for addressing JSON fields. Let’s look at them using a variable named SomeData containing the following structure:
Code: Select all
{
"args": {
"Globals": {
"From": {
"Email": "example@domain.com",
"Name": "Example User"
},
"Bcc": [
{ "Email": "bcc@domain.com" }
]
},
"Messages": [
{
"To": [{ "Email": "user1@test.com" }],
"Files": ["doc1.pdf"]
},
{
"To": [{ "Email": "user2@test.com" }],
"Files": ["doc2.pdf"]
}
],
"SandboxMode": true
}
}The most intuitive way to access data is by using a "dot" to separate levels of the hierarchy.
- Accessing an object: {json:SomeData.args.Messages} returns the entire array found in the Messages field.
- Accessing an array element: {json:SomeData.args.Messages[0]} returns the first object (index 0) of the Messages array.
- Deep nesting: {json:SomeData.args.Messages[0].To[0].Email} drills down to the email address of the first recipient in the first message.
Cons: This method will fail if a field name contains special characters like spaces or dots (e.g., "User Name" or "item.id"), which are technically valid in JSON.
Method 2: Bracket Notation (Python-style)
To handle complex field names or to ensure maximum compatibility, you can use square brackets and quotes. This is the preferred method when dealing with REST APIs that might return "unfriendly" key names.
- Standard access: {json:SomeData["args"]["Messages"]}
- Array access: {json:SomeData["args"]["Messages"][0]}
- Deep nesting: {json:SomeData["args"]["Messages"][0]["To"][0]["Email"]}
Why use Bracket Notation?
In modern web services, you might encounter JSON keys like this: { "Service Status": "OK", "v1.0.attribute": "value" }
- Dot notation would break here because {json:Variable.Service Status} would be interpreted as a variable named Variable.Service followed by the text Status.
- Bracket notation handles it perfectly: {json:Variable["Service Status"]} or {Variable["v1.0.attribute"]}.
Code: Select all
Feature | Dot Notation | Bracket Notation
---------------------------------------------------------------------------------
Syntax Example | Data.field | Data["field"]
---------------------------------------------------------------------------------
Readability | High | Moderate
---------------------------------------------------------------------------------
Supports Spaces | No | Yes
---------------------------------------------------------------------------------
Supports Dots in Names | No | Yes
---------------------------------------------------------------------------------
Best Use Case | Simple, standard JSON | REST API responses, complex keys