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
- Parse structured data from LLM responses in agent pipelines reliably
- Handle inconsistent JSON formatting across different model providers
- Build robust agent tool call parsers that handle malformed outputs
- Pre-process LLM outputs before passing to JSON Schema validation
API Reference
POST https://slopshop.gg/v1/llm-output-extract-json
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Input parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
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.
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."}'
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}"}'
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 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