snipSmart – AI Cleanup Tool


AI has become our assistant in almost everything. Personally, I love using AI to learn — it helps me verify my understanding and feels almost like talking to a human.
But when it comes to GenAI-output, things can get frustrating. We just want clean output — no explanations, no extra text, just the data.
The Problem
Recently, I was building a candidate engagement bot. I needed to extract { skill: proficiency }
pairs from a job description using AI. Despite my strict prompts —
"The output should strictly be a JSON. No additional explanations or text."
AI still responded with something like:
"Sure! Here is the JSON you asked: { skill: proficiency }"
So I had to write fallback logic just to extract the actual JSON and ignore the fluff.
The Solution: snipSmart
That’s when snipSmart was born.
It’s a lightweight, open-source utility that lets you extract clean JSON or HTML/XML snippets from messy AI-generated content. No dependencies. Just copy the function(s) you need and drop them into your project.
You pass in a string — it could be an AI response, raw content, or any noisy input — and the tool:
Cleans out irrelevant text
Extracts the valid JSON or tag-based content
Ensures it can be parsed safely (e.g., with
JSON.parse
)
If the result status is "success"
, you can confidently use it as-is in your code. No more parsing errors or weird edge cases.
How to Use snipSmart
There are 3 ways to use the tool, depending on what you need:
✅ Option 1: Use snipSmart
(Recommended)
This unified function internally calls snipJson
or snipByTag
based on the format
you provide ("json"
or "tag"
).
import snipSmart from "./src/index.js";
const input = `Broken JSON: { "name": "Alice", "age": 30 `;
const result = snipSmart(input, { format: "json" }); // Or format : "tag"
console.log(result);
✅ Option 2: Use snipJson
Directly
Use this if you only need JSON cleanup.
import snipJson from "./src/snipJson.js";
const input = `Here's the object you asked for: { "id": 1, "status": "active" } 😊`;
const result = snipJson(input);
console.log(result);
✅ Option 3: Use snipByTag
Directly
Use this for HTML/XML snippets.
import snipByTag from "./src/snipByTag.js";
const input = `Some markup: <div><p>Hello <b>World</p>`;
const result = snipByTag(input);
console.log(result);
All functions return an object like:
{
status: "success" | "fail" | "check",
comments: "Info or error message",
data: <extracted_snippet_or_null>,
raw: <optional raw fragment>
}
🧪 Test Cases
Here are a few cases from the /testCases
folder.
Input | Format | Output | Status | |
Hello, here's your data: { "a": 1, "b": 2 } | json | { "a": 1, "b": 2 } | ✅ | |
Here is the info: <note><to>User</to></note> | tag | <note><to>User</to></note> | ✅ | |
{ "a": [1, 2 }, "b": 3 | json | Fails due to bracket mismatch | ❌ | |
Just some text, nothing valid | json | No valid JSON structure found | ❌ | ❌ |
<div><span>Text</div> | tag | Mismatched closing tag: expected </span> but found </div> | ❌ |
You can view all test cases here
snipSmart is free, open-source, and built with simplicity in mind.
Feel free to use the code in your own projects, suggest improvements, or contribute new features.
More snips are in the pipeline — stay tuned! ✨
📜 This tool is licensed under the MIT License. If you reuse or share the code, please retain the license notice.
Subscribe to my newsletter
Read articles from shiny sherbina directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
