# Objects Blocks

## Overview

The objects blocks allow you to organize and manage information as structured entities, like pieces of data bundled together. You can use these blocks to create and handle collections of related information.&#x20;

The objects blocks are often used in conjunction with [Web API Blocks](/blocks/advanced-app-features/web-api.md), the [Map Component](/app-design/ui-components/embed-components/map.md) and [Location Sensors](/blocks/app-features/sensors-blocks/location-sensor.md), which often send data in object format.&#x20;

## Set Property of Object to

The "set property of object to" block allows you to change the value of a single property of an object.

<div align="left"><figure><img src="/files/AwaLdBUkNOV36BURRcTz" alt="" width="464"><figcaption></figcaption></figure></div>

## Get Property of Object

The "get property of object" block allows you to read the value of an object's property. If the object does not have a property with this name, it will return "undefined."

<div align="left"><img src="/files/-MOetVgNgQmHMSLLVy3i" alt="" width="375"></div>

### Get Property of Nested Object <a href="#nested-values-and-values-from-arrays" id="nested-values-and-values-from-arrays"></a>

The "get property of object" block can be used to get nested values, i.e. properties of properties of an object. If you are trying to get nested property **b** of property **a** of an object, you can simply get property **a.b** of an object, instead of using multiple "get property of object" blocks.

Below are two example of getting a property of a nested object. The first is presented with the object written in JSON format and the second is created with objects blocks, but both sets of blocks do exactly the same thing. Each will return 5.

<figure><img src="/files/omHyEXqcNvozz6irzDPf" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/cdEPH2RkxeOHXg1ziREd" alt=""><figcaption></figcaption></figure>

### Get Property from an Array <a href="#nested-values-and-values-from-arrays" id="nested-values-and-values-from-arrays"></a>

You can also get a value from an array (or list) of values. If an object property **b** is a 3-items list, and you want to get the second item of that list, you can get property **b\[2]** of that object. The first item of the list is at index 1.

Below are two example of getting a property from an array. The first is presented with the object written in JSON format and the second is created with objects blocks, but both sets of blocks do exactly the same thing. Each will return 6.

<figure><img src="/files/Lasi6qP4UkS0EB5CfqgL" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/3eDzKDPP22lHAy9etZ7M" alt=""><figcaption></figcaption></figure>

### Get Property from Nested Array

The "get property of object" block can also be used to get a property from an array that is a nested property of an object.&#x20;

Below are two example of getting a property from an array that is a nested property of an object. The first is presented with the object written in JSON format and the second is created with objects blocks, but both sets of blocks do exactly the same thing. Each will return 7.

<figure><img src="/files/CSzQXaWZoxBvgJV5TRnK" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/c8rDPCcLK7ZcfcQE20uk" alt=""><figcaption></figcaption></figure>

## Get Object from JSON

If an [API](/blocks/advanced-app-features/web-api.md) returns a JSON (JavaScript Object Notation) value, you can convert it to an object using the "get object from JSON" block.&#x20;

<div align="left"><figure><img src="/files/q7TjVZPHhnH82wJAaThv" alt="" width="267"><figcaption></figcaption></figure></div>

## Generate JSON from Object

To convert an object to JSON to make an API POST or set headers or query parameters for your API call use the "generate JSON from object" block.

<div align="left"><figure><img src="/files/Lf1e2wiSI2qrrJDrCZkN" alt="" width="324"><figcaption></figcaption></figure></div>

## Create Object

The "create object" block allows you to create a new object. Once created, objects can be uploaded to your [Firebase Realtime Database](/blocks/blocks/variables-overview/variables.md#connecting-a-firebase-realtime-db-to-your-app) as the value of a [cloud variable](/blocks/blocks/variables-overview/variables.md#cloud-variables).

To add additional properties to the object:

1. Drag the "create object" block into your workspace.
2. Click the gear icon.<br>

   <div align="left"><figure><img src="/files/TuagQQ0A6T6eWg0UTSkq" alt="" width="234"><figcaption></figcaption></figure></div>
3. In the open modal, drag as many empty property fields as you need from the left and connect them to the block on the right.&#x20;
4. Click inside the newly connected block to type the name of the property field.
5. Click the gear icon when you're done adding property fields.

## Get Object Properties of

The "get object properties of" block returns a list of property names for an object. It is often used with [list](/blocks/blocks/lists.md) blocks.

<div align="left"><img src="/files/-MBj9Rsiu3foEXqwieYa" alt="" width="188"></div>

## Objects Blocks in Action

Objects blocks are often used when making calls to an API. It's common for an API to provide you with a large amount of data in JSON format, similar to the following:

<pre><code>{
  "response": {
    "version": "0.1",
    "termsofService": "http://www.wunderground.com/weather/api/d/terms.html",
    "features": {
      "conditions": 1
    }
  },
  "current_observation": {
    "image": {
      "url": "http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png",
      "title": "Weather Underground",
      "link": "http://www.wunderground.com"
    },
    "display_location": {
      "full": "San Francisco, CA",
      "city": "San Francisco",
      "state": "CA",
      "state_name": "California",
      "country": "US",
      "country_iso3166": "US",
      "zip": "94101",
      "latitude": "37.77500916",
      "longitude": "-122.41825867",
      "elevation": "47.00000000"
    },
    "observation_location": {
      "full": "SOMA - Near Van Ness, San Francisco, California",
      "city": "SOMA - Near Van Ness, San Francisco",
      "state": "California",
      "country": "US",
      "country_iso3166": "US",
      "latitude": "37.773285",
      "longitude": "-122.417725",
      "elevation": "49 ft"
    },
    "estimated": {},
    "station_id": "KCASANFR58",
    "observation_time": "Last Updated on June 27, 5:27 PM PDT",
    "observation_time_rfc822": "Wed, 27 Jun 2012 17:27:13 -0700",
    "observation_epoch": "1340843233",
    "local_time_rfc822": "Wed, 27 Jun 2012 17:27:14 -0700",
    "local_epoch": "1340843234",
    "local_tz_short": "PDT",
    "local_tz_long": "America/Los_Angeles",
    "local_tz_offset": "-0700",
    "weather": "Partly Cloudy",
    "temperature_string": "66.3 F (19.1 C)",
    "<a data-footnote-ref href="#user-content-fn-1">temp_f</a>": 66.3,
    "temp_c": 19.1,
    "relative_humidity": "65%",
    "wind_string": "From the NNW at 22.0 MPH Gusting to 28.0 MPH",
    "wind_dir": "NNW",
    "wind_degrees": 346,
    "wind_mph": 22.0,
    "wind_gust_mph": "28.0",
    "wind_kph": 35.4,
    "wind_gust_kph": "45.1",
    "pressure_mb": "1013",
    "pressure_in": "29.93",
    "pressure_trend": "+",
    "dewpoint_string": "54 F (12 C)",
    "dewpoint_f": 54,
    "dewpoint_c": 12,
    "heat_index_string": "NA",
    "heat_index_f": "NA",
    "heat_index_c": "NA",
    "windchill_string": "NA",
    "windchill_f": "NA",
    "windchill_c": "NA",
    "feelslike_string": "66.3 F (19.1 C)",
    "feelslike_f": "66.3",
    "feelslike_c": "19.1",
    "visibility_mi": "10.0",
    "visibility_km": "16.1",
    "solarradiation": "",
    "UV": "5",
    "precip_1hr_string": "0.00 in ( 0 mm)",
    "precip_1hr_in": "0.00",
    "precip_1hr_metric": " 0",
    "precip_today_string": "0.00 in (0 mm)",
    "precip_today_in": "0.00",
    "precip_today_metric": "0",
    "icon": "partlycloudy",
    "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
    "forecast_url": "http://www.wunderground.com/US/CA/San_Francisco.html",
    "history_url": "http://www.wunderground.com/history/airport/KCASANFR58/2012/6/27/DailyHistory.html",
    "ob_url": "http://www.wunderground.com/cgi-bin/findweather/getForecast?query=37.773285,-122.417725"
  }
}
</code></pre>

In the block combination below, when the screen starts, it calls the [web API](/blocks/advanced-app-features/web-api.md) and receives the response, status, and error outputs. If an error occurs, the label's text is set to the error output message. If no error occurs, the JSON response output is converted to an object. From that object, the nested "temp\_f" property of the "current\_observation" property is joined with "°F" to populate the label's text.&#x20;

![](/files/uPxtdE2mQ6Ky2AyJnMlz)

[^1]:


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.thunkable.com/blocks/blocks/objects.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
