Open Navigation

Intro to data and jsonpaths

The main feature of Tray.io is that it allows you to access individual data items from service A, and insert them into service B. To use these data items, you first must familiarize yourself with some key concepts regarding data.

This will enable you to understand how data is being returned to your workflows, so that you are able to access it in the way that you need.

Exactly how the data is returned (in terms of fields and volume/complexity of data) depends on the service, but the format it is returned in is in accordance with the concepts outlined below.

Introduction to JSON

When you are using service connectors and triggers in Tray.io, they will return data in JSON format.

So what exactly is JSON?

JSON is simply a format for displaying data, using { } , and [ ] to separate and group the data together.

The following is an example of some data on a certain individual, John Doe, output in JSON format

{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : { "streetAddress": "Love Street", "city": "Nara", "postalCode": "630-0192" },
"phoneNumbers": [
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]
}

Fields

The most basic field types are string (plain text) (e.g. "firstName": "John",) and number (e.g. "age": 26,)

Note that a string is contained in " " while a number is not.

Also note that sometimes a number is a string! For example, "number": "0123-4567-8888" This will depend on how the data is stored and returned by the service you are working with.

Please see here for more information on JSON data types.

Objects

When you see multiple fields appear within one set of { } this is what is called an Object.

In the above example, address is an object which contains streetAddress, city and postalCode:

"address" : { "streetAddress": "Love Street", "city": "Nara", "postalCode" : "630-0192" },

In programming and databases, objects are used to enforce a uniform structure, i.e. an 'address' object must always contain streetAddress, city and postalCode.

Arrays

When you see a list of fields or objects appear within [ ], this is what is called an Array.

Array is just a fancy name for 'list'!

An array could be as simple as a list of names, such as:

"cars":[ "Ford", "BMW", "Fiat" ]

Arrays of objects

In the above example you can see that John Doe has an 'array' of phoneNumbers.

Each of these phoneNumbers is an object which contains a type and a number:

"phoneNumbers": [
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]

In data recieved from services, it is likely that the person (i.e. John Doe) will also be an object within an array of objects.

For example you could have an array of customers or an array of employees:

{
"employees": [
{
"firstName": "John",
"lastName": "doe",
"age": 26,
"address": {
"streetAddress": "Love Street",
"city": "Nara",
"postalCode": "630-0192"
},
"phoneNumbers": [
{
"type": "iPhone",
"number": "0123-4567-8888"
},
{
"type": "home",
"number": "0123-4567-8910"
}
]
},
{
"firstName": "Roger",
"lastName": "Ramjet",
"age": 32,
"address": {
"streetAddress": "Acacia Avenue",
"city": "New York",
"postalCode": "624-1082"
},
"phoneNumbers": [
{
"type": "android",
"number": "1111-2222-3333"
},
{
"type": "home",
"number": "4444-5555-6666"
}
]
}
]
}

Next: Learn how to move data between connectors with jsonpaths

Was this article helpful?
Yes
No