Skip to main content

Intro to JSON

Learn how to use JSON in your workflows.


Overview

Triggers and nodes in your workflows return data in JSON format. But what exactly is JSON?

JSON (JavaScript Object Notation) is a lightweight data format commonly used for representing structured data. It provides a simple and readable way to store and exchange information.

JSON is based on key-value pairs and supports various data types, including strings, numbers, booleans, arrays, and objects. Data in JSON is organized in a hierarchical manner, allowing nested structures and complex data relationships.

JSON uses curly braces { } to define objects, and square brackets [ ] to denote arrays. Each key-value pair in an object is separated by a colon (:), and individual elements in an array are separated by commas (,).

Here's an example of JSON data representing information about a book written by J.K. Rowling,

{
"title": "Harry Potter and the Philosopher's Stone",
"author": "J.K. Rowling",
"publicationYear": 1997,
"publisher": {
"name": "Bloomsbury Publishing",
"location": "London"
},
"genre": ["Fantasy", "Adventure"],
"books": [
{
"title": "Harry Potter and the Chamber of Secrets",
"publicationYear": 1998
},
{
"title": "Harry Potter and the Prisoner of Azkaban",
"publicationYear": 1999
},
{
"title": "Harry Potter and the Goblet of Fire",
"publicationYear": 2000
}
]
}

For more information on JSON, please refer to this resource: Working with JSON - MDN Web Docs

Fields

The fundamental field types in JSON include strings, representing plain text (e.g., "author": "J.K. Rowling"), and numbers (e.g., "publicationYear": 1997).

It's important to note that a string is enclosed in double quotation marks (" "), while a number is not.

However, it's worth mentioning that sometimes a number can be represented as a string. For instance, in the case of "number": "0123-4567-8888", the number is stored as a string. This behavior may vary depending on how the data is stored and returned by the specific service you are working with.

Objects

When there is a group of multiple fields enclosed within a set of curly braces { }, it is referred to as an Object.

In below example, the publisher field represents an object that includes the properties name and location:

{
"publisher": {
"name": "Bloomsbury Publishing",
"location": "London"
}
}

Arrays

When there is a group of fields or objects enclosed within square brackets [ ], it is referred to as an Array. An array is simply a collection or a list of items.

An array can represent a simple list, such as:

{
"genre": ["Fantasy", "Adventure"]
}

Arrays of objects

Array of objects are groups of objects enclosed within square brackets [ ]. In below example, there is an array of books. Each of these books is an object that contains a title and a publicationYear:

{
"books": [
{
"title": "Harry Potter and the Chamber of Secrets",
"publicationYear": 1998
},
{
"title": "Harry Potter and the Prisoner of Azkaban",
"publicationYear": 1999
},
{
"title": "Harry Potter and the Goblet of Fire",
"publicationYear": 2000
}
]
}

It is likely that the data you receieve from your services will contain an object containing 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"
}
]
}
]
}