# Working with Structured Data (JSON)

{% embed url="<https://youtu.be/RKsgA5LLnuI>" %}

JSON (JavaScript Object Notation) is a powerful and widely used format for storing and exchanging structured data. In MindStudio, understanding how to parse, generate, and utilize JSON is essential for building flexible and powerful AI workflows.

### What is JSON?

JSON is a structured data format made up of **key-value pairs**. Each key is a string (in quotes), and its associated value can be:

* A string (`"Alice"`)
* A number (`30`)
* A boolean (`true`)
* An array (`["user", "admin"]`)
* Another object (`{"age": 30, "active": true}`)

JSON also supports **nesting**, allowing you to build complex hierarchies of data.

#### JSON Syntax Rules

1. All keys must be strings (in double quotes).
2. Key-value pairs must be comma-separated.
3. Do not include a trailing comma at the end of the last key-value pair.

### Using JSON in MindStudio Workflows

#### Receiving JSON from Blocks

Many blocks, like **Search Google News**, return data as JSON. This allows you to access structured results, such as article titles, links, and thumbnails.

You can:

* Display the full JSON
* Extract specific values using path expressions
* Iterate through lists using `each` blocks

#### Accessing Individual Values

To get a specific value from JSON, use the JSON path:

```
{{GoogleNews.articles[0].title}}
```

This extracts the `title` of the first article from the `GoogleNews` variable.

#### Iterating Through Arrays

Use the `#each` tag to loop through arrays in JSON:

```markdown
{{#each GoogleNews}}
### {{title}}
[Read Article]({{url}})
![]({{thumbnail}})
---
{{/each}}
```

This will render each article's title, link, and thumbnail using Markdown formatting.

#### Generating JSON with AI

You can use the **Generate Text** block to ask AI to return structured JSON. For example, extracting all URLs from search results:

```json
{
  "links": [
    "https://example.com/1",
    "https://example.com/2"
  ]
}
```

Use an **output schema** to define the format and simplify complex JSON into more usable lists.

### Applying JSON in HTML Templates

JSON can also be applied to generate HTML pages dynamically using the **Generate Asset** block. You can:

* Iterate over content sections
* Conditionally render data like headings, key takeaways, and entities
* Use extracted structured data to build full HTML pages for summaries or reports

Example usage:

* Extract structured information from a Verge article
* Use that data to populate an HTML summary page
* Present it with images, headlines, and lists using embedded JSON paths

### Summary

Understanding JSON enables you to:

* Parse and manipulate structured responses
* Extract only the values you need
* Iterate through complex arrays
* Generate clean structured output from unstructured content
* Build advanced outputs like HTML templates dynamically

Once you master JSON in MindStudio, you'll be able to build significantly more advanced and powerful agents with flexible output formatting and robust data handling.


---

# 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://university.mindstudio.ai/2-workflow-mastery/working-with-structured-data-json.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.
