Convert Any Text to Structured JSON with AI
Convert Any Text to Structured JSON with AI: A Practical Tutorial
Unstructured text is everywhere — customer emails, support tickets, product descriptions, meeting notes, web scraping output. The challenge has always been turning that messy, free-form content into data your application can actually use. That’s exactly where convert text to structured JSON AI tools have become indispensable for modern developers.
In this tutorial, you’ll learn how to use the Today’s World AI API to extract clean, structured JSON from any text input — no complex NLP pipelines required.
Why Convert Unstructured Text to JSON?
Most real-world data arrives in a format that databases and APIs don’t understand. A customer might write:
“I’d like to return the blue sneakers I bought last Tuesday for $89.99. Order number is 45231.”
Your application needs structured fields like order_id, item, price, and return_reason — not a raw sentence. Manually parsing this at scale is impractical. AI data structuring solves this by understanding the meaning behind text and mapping it to whatever schema you define.
Common use cases include:
- E-commerce: Extracting product attributes from descriptions
- Finance: Pulling figures from reports or emails
- Healthcare: Structuring patient intake notes
- Customer support: Categorizing and tagging tickets automatically
- Document processing: Converting forms, invoices, and receipts into records
If you’re working with documents specifically, you might also find these related posts useful: How to Extract Invoice Data from PDFs Using AI and Parse Receipts Automatically with AI API. Both cover document-specific extraction workflows that complement what we’re building here.
How AI Text-to-JSON Extraction Works
Modern NLP JSON extraction relies on large language models (LLMs) that have been trained to understand context, entities, and relationships within text. Instead of writing brittle regex rules or keyword matchers, you describe the structure you want — and the model fills it in.
The Today’s World AI API takes this a step further by letting you pass a custom schema alongside your input text. The model reads the text, understands it, and returns a JSON object that matches your schema exactly.
Key Concepts Before You Start
- Schema: The JSON structure you want back (fields, types, nesting)
- Prompt context: Optional instructions to guide extraction behavior
- Confidence thresholds: Some fields may return
nullif the model isn’t certain
Getting Started with the Text to JSON API
Before making your first call, you’ll need an API key. You can get started immediately with a free tier, or explore the full reference in the API docs.
Step 1: Define Your Target Schema
Think about what data you need from your text. For our customer return example, the schema might look like:
{
"order_id": "string",
"item_description": "string",
"price": "number",
"return_reason": "string",
"purchase_date": "string"
}
You don’t need to build a formal JSON Schema object — a simple example object with field names and types is enough for the API to understand your intent.
Step 2: Make Your First API Call
Here’s a working example using curl:
curl -X POST https://api.todaysworld.com/v1/extract/json \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d '{
"text": "I'd like to return the blue sneakers I bought last Tuesday for $89.99. Order number is 45231.",
"schema": {
"order_id": "string",
"item_description": "string",
"price": "number",
"return_reason": "string",
"purchase_date": "string"
},
"options": {
"strict_mode": false,
"null_on_missing": true
}
}'
Step 3: Read the Response
A successful response looks like this:
{
"status": "success",
"data": {
"order_id": "45231",
"item_description": "blue sneakers",
"price": 89.99,
"return_reason": null,
"purchase_date": "last Tuesday"
},
"meta": {
"tokens_used": 112,
"model": "twai-extract-v2"
}
}
Notice a few things here. The model correctly parsed "45231" as the order ID even though it wasn’t labeled explicitly. It returned null for return_reason because that information wasn’t present in the text. And it captured "last Tuesday" for purchase_date — you can post-process this into a proper date format downstream.
Advanced Usage: Nested Schemas and Arrays
The unstructured data extraction endpoint supports nested objects and arrays, which is useful when your text contains multiple items or hierarchical data.
Extracting a List of Items
Suppose you’re parsing a bulk order email:
curl -X POST https://api.todaysworld.com/v1/extract/json \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d '{
"text": "Please ship 3 units of SKU-001 (red t-shirt) and 1 unit of SKU-204 (black hoodie, size L) to 42 Maple Street, Austin TX.",
"schema": {
"items": [
{
"sku": "string",
"description": "string",
"quantity": "number",
"size": "string"
}
],
"shipping_address": {
"street": "string",
"city": "string",
"state": "string"
}
}
}'
The API will return a properly nested JSON object with an items array populated for each product mentioned, plus a structured shipping_address object. This kind of extraction would take hours to build manually with traditional parsing logic.
Tips for Better Extraction Results
Getting great results from any text to JSON API comes down to a few practical habits:
Be specific with field names. A field called customer_sentiment is clearer to the model than one called feeling. Descriptive names improve accuracy.
Use strict_mode: true for critical data. When set to true, the API will return an error rather than a partial result if required fields can’t be confidently extracted. This is useful for financial or compliance workflows.
Pass context when the domain is specialized. You can include a context field in the request body with a short description of the domain (e.g., "Medical intake form from a dental clinic"). This nudges the model toward domain-appropriate interpretations.
Validate outputs before storing. Even with high accuracy, treat AI-extracted data as you would any external input — run it through your standard validation layer before writing to a database.
When to Use This vs. Regex or Traditional NLP
Traditional approaches still have their place. If you’re extracting data from a perfectly consistent, machine-generated format, regex or a simple parser is faster and cheaper. But when your input text varies in phrasing, comes from humans, or changes structure over time, AI data structuring wins on flexibility and maintenance cost.
The sweet spot for this API is high-variability, moderate-to-high volume text processing where building and maintaining custom extraction rules would be a continuous engineering burden.
What to Build Next
Once you have reliable JSON extraction in place, the next step is usually connecting it to your data pipeline — feeding results into a database, triggering workflows, or enriching records in a CRM. Check out the API docs for webhook support, batch processing endpoints, and SDKs for Python, Node.js, and Go.
Ready to automate your workflow? Try it free at todaysworld.com/try or get API access on RapidAPI.