DEV Community

Alex
Alex

Posted on

How I Built an API That Turns Messy Text Into Clean JSON (and You Can Use It Free)

Every developer has dealt with messy unstructured text. Receipts, emails, resumes — they all contain structured data trapped in plain text. Regex is brittle. Manual parsing is tedious.

I built StructureAI to solve this. One API call, any text in, clean JSON out.

The Problem

You get text like this:

Receipt from Whole Foods 03/15/2024
Apples $3.99
Milk $5.49
Bread $4.29
Tax $1.18
Total: $14.95
Card ending 4242
Enter fullscreen mode Exit fullscreen mode

You need this:

{
  "merchant": "Whole Foods",
  "date": "2024-03-15",
  "items": [
    { "name": "Apples", "price": 3.99 },
    { "name": "Milk", "price": 5.49 },
    { "name": "Bread", "price": 4.29 }
  ],
  "tax": 1.18,
  "total": 14.95,
  "payment_method": "Card ending 4242"
}
Enter fullscreen mode Exit fullscreen mode

Regex won't cut it. The format varies every time.

The Solution: One API Call

curl -X POST https://api-service-wine.vercel.app/api/extract \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{
    "text": "Receipt from Whole Foods 03/15/2024...",
    "schema": "receipt"
  }'
Enter fullscreen mode Exit fullscreen mode

That's it. The API returns structured JSON with a confidence score. Works for receipts, invoices, emails, resumes, contacts, or custom schemas.

Supported Schemas

Schema What it extracts
receipt Items, totals, dates, merchant
invoice Line items, amounts, due dates
email Sender, subject, body, dates
resume Name, experience, skills
contact Name, email, phone, address
custom You define the fields

Custom Schema Example

Need to extract product reviews? Define your own fields:

curl -X POST https://api-service-wine.vercel.app/api/extract \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{
    "text": "Love this laptop! Battery lasts 12 hours. Screen is gorgeous. Only downside is the keyboard feels mushy. 4/5 stars.",
    "schema": "custom",
    "custom_fields": ["product_type", "pros", "cons", "rating", "sentiment"]
  }'
Enter fullscreen mode Exit fullscreen mode

Returns:

{
  "product_type": "laptop",
  "pros": ["12 hour battery life", "gorgeous screen"],
  "cons": ["mushy keyboard"],
  "rating": "4/5",
  "sentiment": "positive"
}
Enter fullscreen mode Exit fullscreen mode

Free for MCP Users

If you use Claude Desktop or Cursor, install the MCP server and get 10 free requests:

git clone https://github.com/avatrix1/structureai-mcp.git
cd structureai-mcp && npm install && npm run build
Enter fullscreen mode Exit fullscreen mode

Add to your Claude Desktop config:

{
  "mcpServers": {
    "structureai": {
      "command": "node",
      "args": ["/path/to/structureai-mcp/dist/index.js"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Then just ask Claude: "Extract the receipt data from this text: ..."

Pricing

  • Free tier (MCP): 10 requests
  • API key: $2 for 100 requests

Get a key at api-service-wine.vercel.app.


Built by Avatrix LLC. Questions? support@avatrix.co

Top comments (0)