# Working with JSON in Custom Actions

When configuring a Custom Action that expects a response, Adalo requires the response body to be valid **JSON**. If the JSON is not structured correctly, Adalo will not parse it into outputs and may instead display the entire response as a text blob.

#### ✅ JSON Rules

1. **Content Type**\
   The response must be returned with the header:

   ```
   Content-Type: application/json
   ```
2. Responses must always start with `{` and end with `}`.
3. Each key must be wrapped in double quotes:

   ```json
   { "key": "value" }
   ```
4. Multiple key/value pairs are separated by commas:

   ```json
   {
     "image_url": "https://example.com/image.jpg",
     "status": "ok"
   }
   ```
5. The last key/value pair should **not** end with a trailing comma.

***

#### **🧠 General JSON Formatting Rules**

When building a Custom Action body, make sure your data types are written correctly. JSON is strict about which values need quotes.

1. **Strings and Dates**\
   Use **double quotes** around all text and date values.

   ```json
   { "name": "Taylor", "city": "Denver", "date_joined": "2025-10-28" } // ✅ Correct  
   { name: Taylor, city: Denver } // ❌ Missing quotes  
   { "date_joined": 2025-10-28 }  // ❌ Dates must be strings
   ```
2. **Numbers and Booleans**\
   Do **not** use quotes around numbers or true/false values.

   ```json
   { "age": 32, "isMember": true } // ✅ Correct  
   { "age": "32", "isMember": "true" } // ❌ Incorrect — numbers and booleans should not be quoted
   ```
3. **Null Values**\
   Use `null` (without quotes) when a property has no value.

   ```json
   { "nickname": null } // ✅ Correct  
   { "nickname": "null" } // ❌ Incorrect — this is a string, not null
   ```

***

#### ⚡ Common Pitfalls

1. **Escaped JSON**

   ```json
   "{ \"image_url\": \"https://example.com\" }"
   ```

   This looks correct, but it’s actually a JSON *string* containing escaped characters. Adalo will not parse this.

   ✅ Fix: remove the wrapping quotes and escapes.
2. **Missing or Extra Commas**

   ```json
   { "a": 1 "b": 2 }   // ❌ Missing comma
   { "a": 1, "b": 2, } // ❌ Trailing comma
   ```

   Both will cause parsing errors.
3. **Incorrect or Missing Quotes**\
   JSON requires that property names and string values are enclosed in **double quotes**. Using single quotes or missing quotes will cause the request to fail.

   ```json
   { name: "John" }   // ❌ Missing quotes around key  
   { 'name': 'John' } // ❌ Single quotes not valid in JSON  
   { "name": "John" } // ✅ Correct format  
   ```

   Always use **double quotes** for both keys and string values.
4. **Improper Nesting or Unclosed Brackets**\
   Ensure every opening bracket `{` or `[` has a matching closing one.

   ```json
   { "user": { "name": "John", "email": "john@example.com" } } // ✅ Correct  
   { "user": { "name": "John", "email": "john@example.com" }   // ❌ Missing closing bracket  
   ```

***

#### 📌 Best Practices

* Always test the response in a JSON validator before using it in Adalo.
* Keep keys simple and use lowercase with underscores (e.g., `image_url`, `ok`, `message`).
* Configure matching **Outputs** in Adalo with the same names and types as the JSON keys.

***

✨ In short: Adalo will only recognize outputs if the response is valid JSON with proper formatting and the correct Content-Type header.


---

# 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://help.adalo.com/integrations/custom-actions/working-with-json-in-custom-actions.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.
