Agent Tools 1 credit COMPUTE

Extract JSON from LLM API

Extract valid JSON from messy LLM outputs via REST API. LLMs frequently wrap JSON in markdown code fences, add explanatory text before and after, use single quotes, or include trailing commas — this API strips all of that and returns clean, parseable JSON.

Try it live →

How it works

POST the raw LLM output string. The API tries multiple extraction strategies in order: strip markdown code fences, extract the largest JSON-like substring, fix common syntax errors (single quotes, trailing commas, missing braces), and return valid JSON.

Use cases

API Reference

POST https://slopshop.gg/v1/llm-output-extract-json
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Input parameters

ParameterTypeRequiredDescription
input string | object required The input data to process

Example response

{
  "data": {
    "result": "success",
    "processed": true
  },
  "meta": {
    "credits_used": 1,
    "engine": "real",
    "ms": 4
  }
}

Examples

Three real-world scenarios showing how developers use Extract JSON from LLM in production.

Example 1
Parse fenced code block
Extract JSON from an LLM response that wrapped it in a markdown code block.
curl -X POST https://slopshop.gg/v1/llm-output-extract-json \
  -H "Authorization: Bearer $SLOPSHOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Here is the structured data:\n```json\n{\"name\": \"Alice\", \"score\": 92}\n```\nLet me know if you need anything else."}'
Example 2
Fix single-quoted JSON
Extract and fix JSON where the LLM used single quotes instead of double quotes.
curl -X POST https://slopshop.gg/v1/llm-output-extract-json \
  -H "Authorization: Bearer $SLOPSHOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "{'name': 'Bob', 'active': true, 'score': 88}"}'
Example 3
Extract from verbose response
Pull the JSON object out of a long explanation with embedded JSON.
curl -X POST https://slopshop.gg/v1/llm-output-extract-json \
  -H "Authorization: Bearer $SLOPSHOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Based on my analysis, the sentiment data is: {\"sentiment\": \"positive\", \"confidence\": 0.94, \"aspects\": [\"battery\", \"design\"]}. These results indicate a strong positive response."}'

Code examples

curl

curl -X POST https://slopshop.gg/v1/llm-output-extract-json \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"input": "your data here"}'

Python

import requests

response = requests.post(
    "https://slopshop.gg/v1/llm-output-extract-json",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={"input": "your data here"}
)
result = response.json()
print(result["data"])

Node.js

const response = await fetch("https://slopshop.gg/v1/llm-output-extract-json", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({ input: "your data here" })
});
const { data } = await response.json();
console.log(data);

CLI

# Install the Slopshop CLI
npm install -g slopshop

# Set your API key
export SLOPSHOP_KEY=your_api_key

# Call llm-output-extract-json
slop llm-output-extract-json '{"input": "your data here"}'

Pricing

Credits per call
1
credits
Cost per call
$0.001
at Starter tier
Tier
COMPUTE
Pure compute

Credits are purchased in bundles starting at $1 for 1,000 credits. All compute APIs like this one use 1 credit per call — that's $0.001. See all pricing tiers.

Related APIs in Agent Tools

View the full API catalog · Try in playground · Documentation