Parse JSON - Writer AI Studio

Overview

The Parse JSON block transforms a JSON-formatted string into a structured object that you can work with programmatically. For example, if you have a string like '{"name": "John", "age": 30}', this block converts it into an object where you can access values like object.name or object.age. This block is essential when you need to extract and work with data from:

The parsed object lets you:

Common use cases

How it works

  1. JSON string: Enter the JSON string to parse. You can use variables or state values.

The block parses the string and outputs the resulting object. If the string is not valid JSON, the block raises an error.

Examples

User order form processing

This example shows why parsing JSON is essential for conditional logic and data extraction.

Scenario: A user submits an order form with JSON data that looks like this:

{
  "customer": {
    "name": "Sarah Johnson",
    "email": "sarah@example.com",
    "tier": "premium"
  },
  "items": [
    {"product": "Laptop", "price": 1299.99, "quantity": 1},
    {"product": "Mouse", "price": 29.99, "quantity": 2}
  ],
  "total": 1359.97,
  "shipping_method": "express"
}

Without Parse JSON (problematic):

With Parse JSON (powerful):

  1. UI Trigger → User submits order form
  2. Parse JSON → Converts form data to structured object
  3. Set state → Store parsed data in a state variable called parsed_order
  4. Classification → Check if @{parsed_order.total} >= 1000 for free shipping
  5. Text generation → Use @{parsed_order.customer.name} and @{parsed_order.total} in response

Block Configuration:

Fields

Name Type Control Default Description Options Validation
Plain text Text Textarea - - - -

End states

Below are the possible end states of the block call.

Name Field Type Description
Success - success The request was successful.
Error - error The text provided couldn’t be parsed.

The output of the Parse JSON block is a structured object. You can use this object in the following block with the @{result} variable. To access the values of the object in other blueprint blocks, you can use dot notation. For example, if the object looks like this:

{
  "customer": {
    "name": "Sarah Johnson",
    "email": "sarah@example.com",
    "tier": "premium"
  }
}

@{result.customer.name} will return the value of the name property of the customer object.