DEV Community

Alex
Alex

Posted on

Extract JSON from Any Text in One Command

Regex is fragile. Every new text format breaks your parser. You spend more time maintaining extraction logic than building features.

There's a better way: send the text to an API, get clean JSON back. One command. Any format.

The One-Liner

curl -X POST https://api-service-wine.vercel.app/api/extract \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{
    "text": "John Smith, john@example.com, +1-555-0123, Software Engineer at Google",
    "schema": "contact"
  }'
Enter fullscreen mode Exit fullscreen mode

Response:

{
  "data": {
    "name": "John Smith",
    "email": "john@example.com",
    "phone": "+1-555-0123",
    "title": "Software Engineer",
    "company": "Google"
  },
  "confidence": 0.98
}
Enter fullscreen mode Exit fullscreen mode

No regex. No parsing logic. No maintenance.

Built-in Schemas

The API comes with schemas for common data types:

Receipts

curl -X POST https://api-service-wine.vercel.app/api/extract \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{
    "text": "Target Store #1234 03/07/2026\nBananas $1.29\nMilk 2% $4.99\nEggs Large $3.49\nSubtotal $9.77\nTax $0.83\nTotal $10.60\nVisa ***4242",
    "schema": "receipt"
  }'
Enter fullscreen mode Exit fullscreen mode

Returns items, totals, tax, merchant, date, and payment method — all structured.

Resumes

curl -X POST https://api-service-wine.vercel.app/api/extract \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{
    "text": "Jane Doe\njane.doe@email.com\n\nExperience:\nSenior Developer at Netflix (2022-present)\n- Led migration from REST to GraphQL\n- Reduced API latency by 40%\n\nFrontend Developer at Uber (2019-2022)\n- Built driver dashboard in React\n\nSkills: TypeScript, React, GraphQL, Node.js, AWS",
    "schema": "resume"
  }'
Enter fullscreen mode Exit fullscreen mode

Returns structured experience, skills, education, and contact info.

Emails

curl -X POST https://api-service-wine.vercel.app/api/extract \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{
    "text": "From: alice@company.com\nTo: bob@company.com\nDate: March 7, 2026\nSubject: Q1 Budget Review\n\nHi Bob, attached is the Q1 budget. We are 15% over on marketing spend. Can we discuss Thursday at 2pm? - Alice",
    "schema": "email"
  }'
Enter fullscreen mode Exit fullscreen mode

Extracts sender, recipient, date, subject, action items, and key metrics.

Custom Schemas

Need to extract something specific? 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": "Property at 123 Oak St, Austin TX. 3 bed 2 bath, 1,850 sqft. Built 1995. Listed at $425,000. HOA $250/month. Central AC, hardwood floors, updated kitchen.",
    "schema": "custom",
    "custom_fields": ["address", "bedrooms", "bathrooms", "sqft", "year_built", "price", "hoa_fee", "features"]
  }'
Enter fullscreen mode Exit fullscreen mode

Returns:

{
  "address": "123 Oak St, Austin, TX",
  "bedrooms": 3,
  "bathrooms": 2,
  "sqft": 1850,
  "year_built": 1995,
  "price": 425000,
  "hoa_fee": 250,
  "features": ["Central AC", "hardwood floors", "updated kitchen"]
}
Enter fullscreen mode Exit fullscreen mode

The API figures out the types automatically. Numbers come back as numbers, arrays as arrays.

Building a CLI Wrapper

For frequent use, wrap it in a shell function. Add to your .bashrc or .zshrc:

extract() {
  local schema=${2:-custom}
  local text="$1"

  curl -s -X POST https://api-service-wine.vercel.app/api/extract \
    -H "Content-Type: application/json" \
    -H "X-API-Key: $STRUCTUREAI_KEY" \
    -d "{
      \"text\": \"$text\",
      \"schema\": \"$schema\"
    }" | jq '.data'
}
Enter fullscreen mode Exit fullscreen mode

Now you can run:

extract "John Smith, john@example.com, Engineer at Google" contact
extract "Bananas $1.29, Milk $4.99, Total $6.28" receipt
Enter fullscreen mode Exit fullscreen mode

Piping Data

The real power is in pipelines. Extract data from files, logs, or command output:

# Extract from a file
cat receipt.txt | xargs -I {} curl -s -X POST \
  https://api-service-wine.vercel.app/api/extract \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $STRUCTUREAI_KEY" \
  -d '{"text": "{}", "schema": "receipt"}'

# Process multiple files
for f in receipts/*.txt; do
  echo "=== $f ==="
  extract "$(cat $f)" receipt
done
Enter fullscreen mode Exit fullscreen mode

Use in Node.js

async function extractData(text: string, schema: string) {
  const response = await fetch('https://api-service-wine.vercel.app/api/extract', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-Key': process.env.STRUCTUREAI_KEY!,
    },
    body: JSON.stringify({ text, schema }),
  });
  const result = await response.json();
  return result.data;
}

// Usage
const contact = await extractData(
  'Jane Doe, jane@test.com, CTO at Stripe',
  'contact'
);
console.log(contact.name);  // "Jane Doe"
console.log(contact.title); // "CTO"
Enter fullscreen mode Exit fullscreen mode

Use in Python

import requests

def extract_data(text, schema="custom", fields=None):
    payload = {"text": text, "schema": schema}
    if fields:
        payload["custom_fields"] = fields

    response = requests.post(
        "https://api-service-wine.vercel.app/api/extract",
        json=payload,
        headers={"X-API-Key": STRUCTUREAI_KEY}
    )
    return response.json()["data"]

# Usage
receipt = extract_data(
    "Whole Foods: Apples $3.99, Bread $4.29, Total $8.28",
    schema="receipt"
)
print(receipt["total"])  # 8.28
Enter fullscreen mode Exit fullscreen mode

Pricing

An API key costs $2 and gives you 100 requests. That's $0.02 per extraction. No subscriptions, no monthly fees.

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

For Claude Desktop users, the MCP server includes 10 free requests. Just ask Claude to extract data from any text.

When to Use This vs. Regex

Use regex when the format is fixed and simple (parsing CSV, matching emails). Use structured extraction when the format varies, the data is complex, or you need to handle edge cases gracefully.

The API handles messy, inconsistent, real-world text. Regex handles clean, predictable patterns. Pick the right tool.


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

Top comments (0)