Working with JSON

Learn about structured data with JSON.

What Is JSON in MindStudio?

  • JSON (JavaScript Object Notation) is a lightweight data-interchange format

  • JSON lets you structure AI output as key–value pairs, making it easy to parse, display, or export to other systems.

  • Represents data as nested objects and arrays

  • Ideal for:

    • Structured reports or catalogs

    • Data exports (to CSV, spreadsheets, databases)

    • Downstream logic (conditionals, integrations)

JSON Fundamentals Cheat-Sheet

Syntax
Meaning

{ … }

Object (holds key–value pairs)

"key": value,

Key–value pair (separated by commas)

"string"

String (always in quotes)

123

Number (no quotes)

true/false

Boolean

[ … ]

Array (ordered list of items)


Enable JSON Output

Open your Generate Text block.

Under Output Schema, select JSON instead of Text. A Sample Output editor appears—this is where you define your JSON template.

Define Your JSON Template

In Sample Output, sketch the shape of your response:

{
  "title": "Strong, provocative",
  "subtitle": "",
  "body": "Up to 50 words",
  "call_to_action": "",
  "image_prompt": "Prompt for AI to generate background image"
}
  • Keys (e.g., title, body) define fields your AI will fill.

  • Values can be placeholders or examples guiding the model’s output.

  • Empty strings ("") let the AI choose content freely.

Extracting a Value from a JSON Structure

MindStudio provides tools for extracting specific values from JSON objects using the JSON Path syntax and the get helper. This allows workflows to handle and manipulate structured data with precision, making them more dynamic and adaptable.


get Helper - Query JSON Variables

The get helper allows you to query JSON variables for specific values using JSON Path expressions. This feature is especially useful when working with nested or complex JSON structures.

Syntax:

{{get myVariable "$.path.to.value"}}

Example 1: Extract a Nested Value:

Given the following JSON assigned to myJsonVariable:

{
    "user": {
        "name": "Alice",
        "details": {
            "email": "[email protected]"
        }
    }
}

Use this to extract the email address:

{{get myJsonVariable "$.user.details.email"}}

Output: [email protected]


Example 2: Extract the First Item in an Array:

Given the following JSON:

{
    "items": [
        {"id": 1, "name": "Foo"},
        {"id": 2, "name": "Bar"}
    ]
}

Use this to extract the name of the first item:

{{get myJsonVariable "$.items[0].name"}}

Output: Foo


Example 3: Extract Multiple Values:

JSON Path also allows for querying multiple elements. Given the following JSON:

{
    "items": [
        {"id": 1, "name": "Foo"},
        {"id": 2, "name": "Bar"}
    ]
}
{{get myJsonVariable "$.items[*].name"}}

Output: ["Foo", "Bar"]


Best Practices When Extracting JSON

  1. Use a JSON Path Tester: Tools like JSONPath Online Evaluator can help you refine and test your JSON Path queries.

  2. Validate JSON Structure: Ensure your variable contains valid JSON data before attempting to extract values.

  3. Handle Missing Values: Include fallback logic in your workflow to handle cases where the expected path does not exist in the JSON.

Last updated